Javascript tag documentation

You can customize the javascript tag in Piwik and improve the way Piwik tracks your visitors and actions.

Customize the ‘action’ name displayed in Piwik

By default Piwik uses the URL of the current page as the ‘action’ name in the Piwik interface. If your URLs are not simple, or if you want to customize the way Piwik tracks your pages, you can specify the action name to use in the Javascript tag.

A common way is to use the HTML Title value:

[...]
piwik_action_name = document.title;
piwik_idsite = 1;
piwik_url = ‘http://yourwebsite/piwik/piwik.php’;
piwik_log(piwik_action_name, piwik_idsite, piwik_url);
[...]

Advanced users can also print any generated title value, for example in PHP:

[...]
piwik_action_name = “<?php echo $myPageTitle; ?>”;
piwik_idsite = 1;
[...]

Changing the list of files extensions to track as “downloads”

By default, any file ending with one of these extensions: 7z|aac|avi|csv|doc|exe|flv|gif|gz|jpe?g|js|mp(3|4|e?g)|mov|pdf|phps|png|ppt|rar|
sit|tar|torrent|txt|wma|wmv|xls|xml|zip
will be considered a “download” in the Piwik interface.

To change the list of extensions you want to track as file downloads, you can set a new javascript variable:

[...]
piwik_url = ‘http://yourwebsite/piwik/piwik.php’;
piwik_download_extensions = “jpg|png|gif”; // we now track only clicks on image
piwik_log(piwik_action_name, piwik_idsite, piwik_url);
[...]

Consider a host an “alias” host and not record the links to this domain as “outlinks”

By default all links to domains other than the current domain are considered outlinks. If you have multiple domains and don’t want to consider links to these websites as “outlinks” you can add this new javascript variable:

[...]
piwik_url = ‘http://yourwebsite/piwik/piwik.php’;
piwik_hosts_alias = ["hostname1.com", "hostname2.com"]; // the current tracked website is added to this array anyway
piwik_log(piwik_action_name, piwik_idsite, piwik_url);
[...]

Changing the pause timer

When a user clicks to download a file, or when he clicks on an outbound link, Piwik records it: it adds a small delay before the user is redirected to the requested file or link. We use a default value of 500ms, but you can set it shorter, with the risk that this time is not long enough to record the data in Piwik.

[...]
piwik_url = ‘http://yourwebsite/piwik/piwik.php’;
piwik_tracker_pause = 250;
piwik_log(piwik_action_name, piwik_idsite, piwik_url);
[...]

Disable the download & outlink tracking

To disable all the automatic downloads and outlinks tracking, you must set a javascript variable:

[...]
piwik_url = ‘http://yourwebsite/piwik/piwik.php’;
piwik_install_tracker = 0;
piwik_log(piwik_action_name, piwik_idsite, piwik_url);
[...]

Ignore a download or outlink tracking on a specific link

If you want to always ignore download or outlink tracking on a specific link, you can add the ‘piwik_ignore’ css class to it:

<a href='last.zip' class=’piwik_ignore’>File I don’t want to track as a download</a>

Force a click on a link to be recorded as a download in Piwik

If you want Piwik to consider a given link as a download, you can add the ‘piwik_download’ css class to the link:

<a href='last.php' class=’piwik_download’>Link I want to track as a download</a>

Force a click on a link to be recorded as an outlink in Piwik

If you want Piwik to consider a given link as an outlink (links to the current domain or to one of the alias domains), you can add the ‘piwik_link’ css class to the link:

<a href='http://mysite.com/partner/' class=’piwik_link’>Link I want to track as an outlink</a>

Entries (RSS)