Modify the tracking code

Standard Piwik PRO JavaScript tracking code is quite powerful and lets you automatically track most of the activity happening on your website. There are however some things that require either modifying the tracking code in some way or adding it in additional places. Below I’ll describe the most popular use cases.

Please note that examples below are made using the Piwik PRO Tag Manager, but with additional effort can also be achieved without it.

Virtual Pageview

Many modern websites are made as a Single Page Applications (SPA. Standard Piwik PRO Javascript tracking code won’t be able to track the movement of visitors on such pages as data is normally sent to Piwik PRO on page reload, which rarely happens in SPA. That’s why it’s a good idea to set up some virtual pageviews whenever content on your website is modified by the actions of visitors. Piwik PRO Tag Manager has you completely covered in this matter. All you need to do is choose the Virtual Pageview tag from the predefined tags list, by clicking the plus icon under the “Tags” tab in your PPTM.

Next, you’ll need to fill some information that you’ll want to be stored in Piwik PRO:

And configure a trigger that will activate the PageView. the “Click” trigger firing whenever the correct click ID is clicked works pretty well in such situation but feel free to experiment with other triggers as well:

And that’s it! just hit the save button, repeat for your other pages and publish to start tracking pageviews.

Custom events

Custom Events are very similar to virtual pageviews, the setup looks almost the same as above but instead of providing URL’s and Page Title, you provide the custom data grouped as Category Action Name and Value.

What you ‘ll store in those fields is up to you. The other difference is that while Virtual Pageviews will be displayed in Piwik in the Actions/Pages report, the Custom Events will be stored in the Actions/Events menu.

Tracking a goal

While Piwik PRO offers some standard option that allows recognizing a goal conversion, you may always want to track goal manually, whenever a condition of your choosing happens. To do that you need to use following method at the moment of conversion:

_paq.push(['trackGoal', <GoalID>]);

Instead of manually pasting this inside of your website code, you can use the Piwik PRO Tag Manager to fire the code for you. First of all, create a new custom HTML tag:

Inside of the Tag HTML Code paste following:

_paq.push(['trackGoal', <GOAL ID>]);

Where <GOAL ID> equals the ID of your goal, this can be found inside of your Analytics section, in the Goals tab under “Manage Goals”.

Next, you need to setup a trigger to choose when the Goal should be converted, for that feel free to use the wide variety of predefined and configurable triggers offered by the Piwik PRO Tag Manager.


Piwik PRO Tag Manager also greatly simplifies tracking of UserID of your visitor. First of all, you’ll need to create a variable that will hold the UserID parameter that you want to pass to Piwik ( ex. user email address).

In this case, the variable is pulling text content from a DOM element signed with ID “username”. This method is by no means a universal one and you’ll need to figure out your own best way to  pass the username to Piwik, but there are a lot of other methods that can be used to pull data from your website, feel free to test PPTM Variables feature to find the best method for your website. And should you find yourself stuck or have any questions, feel free to contact our support.

When you’ll have your variable configured, all you need to do is switch the “Set user ID” switch in your Piwik PRO tag settings:

Was this article helpful?

of people found this helpful

Technical Support

If you have any questions, drop us a line at

We’re happy to help!