Quantcast
Viewing all articles
Browse latest Browse all 4243

Problems tracking Ajax clicks with jQuery (2 replies)

Hi, I wonder if someone can tell me what I'm doing wrong. I have a one page site on which clicks on the nav simply animate content sections into view. I installed Piwik and it tracks page loads no problem, but I'm trying to track navigation clicks as pageviews and can't seem to get it to work.

Here's the click code (fired within a jQuery document ready function of course)

jQuery('.page-item-15 a, #home_art').click(function(e) {
e.preventDefault();
showArt();
_paq.push(['trackPageView', 'art']);
});

The click is registered as a pageview in Piwik, but not for "art," it just registers it for whatever page is physically shown in the browser, so "/index" if I'm on the home page.

I really don't want to add onclick to the link markup like the documentation suggests, isn't this possible from within a jQuery click function? Is there something else that I need to do to make the _paq object fully available there?

Here's the Piwik code loaded in my header too, (I just changed the URL since it's not a live site yet):

var _paq = _paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://MySite.com/piwik//";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 1]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript';
g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();

Thanks in advance for any help!

David

Viewing all articles
Browse latest Browse all 4243

Trending Articles