Piwik tracking and pushState()

Suppose you use the history.pushState() to dynamically change the URL on your ajax web page and you also use Piwik to track your visitors.

When you change the url via the pushState(), Piwik does not know he needs to track the “new page”, as the page did not fully reload and the trackPageView() function was not recalled.

In order to force Piwik to track the page “change” we could add this code to our changeURL() function:

 if (typeof (piwikTracker.trackPageView) == 'function') {
      piwikTracker.setDocumentTitle(title)
      piwikTracker.setCustomUrl(url);
      piwikTracker.trackPageView();
 }

The variables url and title need to be already defined in your code.

Leave a Reply

Please type the characters of this captcha image in the input box

Please type the characters of this captcha image in the input box
Name *
Email *
Website