Trouble tracking AJAX requests


(jjhudson) #1

I am a little confused on how to go about tracking ajax requests with Piwik. I am using jQuery to ajax in content from other content pages I have in a /pages directory onto my main index page. I found a post on piwik-hackers about someone trying to do this with the old javascript tracking code. He claimed he got it to work by including the piwik tracking code in the html that was ajaxed in. When I try this however, my page gets stuck loading and eventually firebug gives me a “too much recursion” error.

Lately I have been trying to execute trackPageView function within the ajax function I use to call the content pages, but have only been successful in recording pageviews for the index page, and not the content page which was ajaxed. There seems to be a lack of documentation on tracking ajax requests, so I am at a loss.

Has anyone successfully implemented the tracking of ajax requests with piwik, and if so, how did you pull it off?


(jjhudson) #2

Still no headway. No one else has had any luck?


(vipsoft) #3

What’s wrong with calling trackLink()?

the alternative is the server side tracking api. an alpha version is in trac.


(jjhudson) #4

[quote=vipsoft @ Sep 16 2009, 04:46 PM]What’s wrong with calling trackLink()?

the alternative is the server side tracking api. an alpha version is in trac.[/quote]

Thanks for the tip, I was able to get my requests tracked with trackLink().


(andras) #5

I’ve tried to use trackLink() to log ajax calls but (correct me if I’m wrong) I have only the choice between ‘link’ and 'download" as linkType.
I would prefer to log these calls as standard “page views” with a specific url (instead of the regular document’s url). Is there a trick to do that ?


(vipsoft) #6

Use setDocumentTitle, setCustomUrl, and trackPageView.


(andras) #7

That’s what I need. Thanks !


(DriverDan) #8

Make sure you put your trackLink() and other Piwik JS requests within a try/catch in case the user actively blocks Piwik (eg with AdBlock).