SOLVED

Re: Track page tag

Go to solution
Anonymous
Not applicable

Re: Track page tag

Hi Sanford, can you please validate my script, somehow the "website visit" trigger is not firing when I write a condition web page contains "all access workplace"

<script type="text/javascript">

  jQuery(function($){

  $.ajax({

   url: document.location.protocol + '//munchkin.marketo.net/munchkin.js',

   dataType: 'script',

   cache: true,

   var MOKeywords=document.head.querySelector('META[name="keywords"]');

   if (MOKeywords) document.location.hash = "MOKeywords:" + MOKeywords.getAttribute('content');

   success: function() {

  Munchkin.init('XXX-YYY-XXX');

   }

  });

  });

  </script>

Way on the top, I have a keyword meta tag defined as:

<meta name="keywords" itemprop="keywords" content="all access workplace,all wireless office,rightsizing,microsoft lync,gigabit wi-fi,wlan,ucc,unified communication,all-wireless" />
SanfordWhiteman
Level 10 - Community Moderator

Re: Track page tag

All your code needs to be in the success: listener (starting with "var..."). I'm sure if you look at your JS console you'll see a syntax error now.

Anonymous
Not applicable

Re: Track page tag

Thanks Sanford. Sorry that I am not a java script guy (already put in an idea to create this as feature).

Is this what you mean

!-- Marketo -->

jQuery(function($){
$.ajax({
url: document.location.protocol + '//munchkin.marketo.net/munchkin.js',
dataType: 'script',
cache: true,

success: listener( {
var MOKeywords=document.head.querySelector('META[name="keywords"]');
if (MOKeywords) document.location.hash = "MOKeywords:" + MOKeywords.getAttribute('content');
});

success: function() {
Munchkin.init('009-RUR-657');
}
});
});

SanfordWhiteman
Level 10 - Community Moderator

Re: Track page tag

I mean literally all the JS I posted goes inside

success: function(){

}

Honestly the fact that you're loading Munchkin asynchronously is making it harder for you to customize the code because you're not a JS guy. You'd be better off using the regular embed code and putting it at the bottom of your HTML.  I'm not always a fan of loading Munchkin.js async because the very thing that makes async attractive -- doesn't interfere with other assets or page rendering/navigation -- is also leaving room for Munchkin to fail to register a page view before the user navigates away from the page. Of course in most cases it's beneficial, but in specific edge cases you might lose a log entry because the page has been told not to wait for Munchkin.js before moving on.

Anonymous
Not applicable

Re: Track page tag

Thank you Sanford, Elliott and Courtney for your support. As a workaround, I could finally add the contents of keywords meta tag into web tracking, and use it as constraints on "Visited Website Filter". Here is the final piece of code. Added two lines highlighted in BOLD.

My page has a meta tag header keywords as defined below:

<meta name="keywords" itemprop="keywords" content="all access workplace,all wireless office,rightsizing,microsoft lync,gigabit wi-fi,wlan,ucc,unified communication,all-wireless" /

Solution that worked for me (recommended by Sanford)

============

<!-- Marketo -->

<script type="text/javascript">

jQuery(function($){

$.ajax({

url: document.location.protocol + '//munchkin.marketo.net/munchkin.js',

dataType: 'script',

cache: true,

success: function() {

var MOKeywords=document.head.querySelector('META[name="keywords"]');

if (MOKeywords) document.location.hash = "MOKeywords:" + MOKeywords.getAttribute('content');

Munchkin.init('XXX-YYY-ZZZ’);

}

});

});

</script>

===========

** Comment from Sanford: Honestly the fact that you're loading Munchkin asynchronously is making it harder for you to customize the code because you're not a JS guy. You'd be better off using the regular embed code and putting it at the bottom of your HTML.  I'm not always a fan of loading Munchkin.js async because the very thing that makes async attractive -- doesn't interfere with other assets or page rendering/navigation -- is also leaving room for Munchkin to fail to register a page view before the user navigates away from the page. Of course in most cases it's beneficial, but in specific edge cases you might lose a log entry because the page has been told not to wait for Munchkin.js before moving on

Alternate sultion suggested by Courtney

** This may log two activity records per website visit

One solution you could consider is to do a quick JavaScript call with this using faux URLs; let's say, for instance, you have

<meta name="product" property="text" content="This is a product" />

As a meta tag in the header of your page. You could do something akin to

===============

<script src='http://munchkin.marketo.net/munchkin.js' type='text/javascript'></script>

<script>

Munchkin.init('###-###-###');

  var x = document.getElementsByTagName("META");

var txt = "";

var i;

for (i = 0; i < x.length; i++) {

    if (x[i].name=="product")

    {

        Munchkin.munchkinFunction('visitWebPage', { url: '/meta-tag/product'});

    }

}

</script>

===========

Where you would have Marketo record a fake URL when someone visits a page with the meta name of product. This code would obviously need to be tweaked to the parameters you're using, but it'll at least generate something in Marketo to generate lists with.

Elliott_Lowe1
Level 9 - Champion Alumni

Re: Track page tag

Deepak - I voted for your Idea.  I'm sure others will too - hint, hint Sanford

Anonymous
Not applicable

Re: Track page tag

Hi Sanford, after I implemented the script, our web team asked not to modify the URL. Unfortunately i need to take the "append to URL" part down.

I am OK posting duplicate URL if I can qualify the second/duplicate URL. Can you please recommend if a mix of your approach and Courtney's approach would work?

I tried below, it does not seem to be logging the second URL: Please help

<script type="text/javascript">
jQuery(function($){
$.ajax({
url: document.location.protocol + '//munchkin.marketo.net/munchkin.js',
dataType: 'script',
cache: true,
success: function() {
Munchkin.init('XXX-YYY-ZZZ’);

var MOKeywords=document.head.querySelector('META[name="keywords"]');
if (MOKeywords) Munchkin.munchkinFunction('visitWebPage', { url: '/MO:meta-tag/' + MOKeywords.getAttribute('content') }); 
}
});
});
</script>
SanfordWhiteman
Level 10 - Community Moderator

Re: Track page tag

I wouldn't use colons in the path part of a URL (even a fake URL).  It runs the risk of screwing up parsing.  Just /meta-tag/servers seems appropriate.

But you're also losing the real page (document.html) and query string.  Why not include that, too? 

Where's your test page for this?

Anonymous
Not applicable

Re: Track page tag

Hi Sanford, appears I am doing something fundamentally wrong.

Our production pages are working fine, able to track visit:

http://www.arubanetworks.com/solutions/all-wireless-workplace/

None of the TEST page is logging activity. There are 7 of them.

http://www.arubanetworks.com/mktotest1.html​ - old tracking code, with URL and keywords. Not working.

http://www.arubanetworks.com/mktotest2.html​ - New tracking code, as-is copied from admin console. In the body tag. Not working.

http://www.arubanetworks.com/mktotest3.html​  - New tracking code, as-is from admin console, outside the body tag.

http://www.arubanetworks.com/mktotest4.html​ - New code, outside body and html tag

http://www.arubanetworks.com/mktotest5.html​ - new code with modified URL

http://www.arubanetworks.com/mktotest6.html​ - New code with document url

http://www.arubanetworks.com/mktotest7.html - new code with keyword

Once these are working successfully, I will combine test code 5, 6 and 7 to get correct logging.

Thanks

Deepak

SanfordWhiteman
Level 10 - Community Moderator

Re: Track page tag

All these errors are are viewable in your browser's console.  You really need to get used to opening the console while you work!

mktotest1.html has a syntax error.  You used a backtick ` instead of a single quote '.

mktotest2.html - mktotest7.html all fail on "$ is not defined."  This is because you did not include the jQuery library on the page, yet you're attempting to use jQuery.ajax().