Tracking API: PHP vs JS

Hi everyone,

Long time Piwik user here. I’ve been doing research on different implementations of Piwik tracking.

I know the recommended tracker is to use the Javascript client. I’ve read about the different implementations that are available though such as using PHP tracking using HTTP requests for example.

What are the pros and cons of using PHP HTTP requests instead of the Javascript tracker???

Are there any speed advantages?
I know one small advantage is the removal of javascript from a page which would allow for an easier implementation of CSP

What do you guys think ?

The Javascript method is asynchronous so shouldn’t slow anything down. It also allows you to get more granular data as well as creating your own variables. using the JS method along with PHP allows us very granular reports.

We use PHP to go through our own Content Security mechanism. This populates various cookies which can then be used to populate various variables in Piwik. For example, once a user logs in we now know who they are and what they do on the site - right down to what buttons they clicked to how far they scrolled down a page.

You just can’t do this stuff with the PHP tracker.

Thanks for the reply Valdhor.
That sounds like a really smart implementation you guys have going.

Would you be willing to share your set up? You’re using PHP for CSP ?

We use our own in-house CSP solution so I can’t share any info on it. Suffice to say a secure login system is used that populates various cookies. These cookies are then read and populate the userid that Piwik uses as well as a few custom variables.

Seeing as our application is a one page application using routing (ie. The part after the # in the url specifies the page) then it is a simple matter to add the tracking code to the routercontroller code:

_paq.push(['setUserId', <user id gleaned from cookie>]);