How to Force a Second trackPageView?


#1

Hi,

I’ve started using Piwik about a week ago. I am using asynchronous tracking, and it is working very well so far, but there is one thing I cannot seem to do. I have a page which allows visitors to slide images in a gallery. I want each image slide action to be tracked as a page view. So I have code that does something like:


_paq.push(	['setDocumentTitle', image-title],
		['setCustomUrl', image-permalink],
		['setEcommerceView', sku, image-title, product-category],
		['trackPageView']
);

But I am finding that no matter how many times this block is called it register only once as a page view, the very first time the page was loaded. I checked server logs, and Piwik is definitely not sending its GET requests each time that block is called, but if I debug and step through the js I can see those above lines are executing. It looks like the tracker is ignoring those requests until a page unload took place.

Now, this might be the expected behaviour, or not, but in either case, how can I force the trackPageView to record a view? I think this is a very desirable scenario to support considering the amount of Web 2.0 sites where no actual page requests take place from the server, yet they are trackable events worthy of an in-depth analysis.

Many thanks,
Rafal


(vipsoft) #2

Piwik submits its tracking requests to the javascript engine as soon as it’s called, using an image request. After that, it’s up to the javascript engine and no longer under Piwik’s control. The browser may queue the request, giving higher priority to something else (eg dom animation), or be stalled by something else in the pipe.

Our unload handler only inserts a delay in case the browser needs more time to process the tracking request that we sent it earlier.

Opera is the worst in my testing, followed by Webkit browsers.


#3

Dear Anthon, thanks for answering. Does it mean that it is impossible to have more than 1 trackPageView without loading another page? Is there, perhaps, something I could call to “flush” or otherwise force the trackPageView? Or do you feel this is a bug, which I should submit?


(vipsoft) #4

There’s no flush()-like function defined in the ECMAScript standard.

Event and DOM recording support is planned for a future Piwik version. This would buffer the data and send it in periodic batches.


#5

Thanks Anthon. Since I cannot find a specification for the trackViewPages call, let me ask you, if it is a correct assumption on my side that it should generate a view each time it is called. Or, perhaps, it is not expected to do that - I am not sure. Depending on your answer I will not only know better what to expect, but I can also log a bug if needed, but it would be pointless for me to log a bug if this is expected behaviour…

Is there a spec or a more detailed write-up of the expected behaviour of this, and other tracking functions, other than the short listing of all the functions under the asynchronous section of the Java Tracking document?

Many thanks,
Rafal


(Matthieu Aubry) #6

Rafal, did you solve your problem? can you produce a snippet to reproduce your problem?


#7

Matt, I had to abandon the asynchronous tracking method. Since I have reverted to the standard approach, I have been able to track second page views. I have new problems with ecommerce cart update not registering, but perhaps those are unrelated.

I have concluded that it is not possible to successfully track a second page view by pushing [trackPageView] onto the array (using the asynch approach) unless there is a “real” page reload/unload event in between. I have gone as far as using the non-minified version of piwik.js, which I peppered with Console.Log() calls and I have stepped through as much as I could using Firebug. I could see that the correct functionality was being called the first time, but not on the subsequent pushes. This was the case in several different browsers tested, including Firefox.

I have actually made notes and a detailed trace with a copy of the piwik.js, and I was going to log it for you as a bug, but, as you can see from this thread, I got an indication from Anthon that perhaps it was something you were aware of as a browser issue. I could not get a confirmation either if this was perhaps the expected functionality, so I deleted the notes and the debugging code and trace. I will avoid asynch tracking for a while, but perhaps I will try again on the next project.


(vipsoft) #8

Sorry, we went in the wrong direction on this thread.

Let’s go back to your first post. Your example shows _paq.push()'ing multiple items.

With asynchronous loading, you can _paq.push() multiple items because _paq is an array. BUT once piwik.js is loaded, _paq is replaced with a proxy object – and push() is simply calling the actual functions in the tracker object. The workaround is to simply _paq.push() each item separately.

For 1.6, I’ll add support for pushing multiple items in the proxy object.


(vipsoft) #9

Fixed in trunk. Thanks.

http://dev.piwik.org/trac/changeset/5031


#10

Dear Anthon,

Thank you, I appreciate your response, very much. I am glad to hear that it was an issue, which you were able to fix. I will re-test the next time I have an opportunity to change my code.

Rafal