Tracking an additional file format

I have successfully implemented Piwik website tracking using the GTM method (i.e. we have a Google container on the site, and we’ve added the Piwik’s ‘Custom HTML’ as a tag in GTM).

Piwik allows to track downloads of plenty of file formats. Unfortunately, the .xz format isn’t among them and we need to add it to the list of tracked format.

Looking into the documentation , I found this guide. It says:

You can customize list of file extensions you want to track as downloads. You can add new extensions, to an existing list with addDownloadExtensions:

// add other image formats
_paq.push(["addDownloadExtensions", "svg|xcf"]);

I’m not very proficient with JavaScript. Exactly where I should add this code (I believe the second parameter should be “xz”) given our GTM setup?

Any response would be highly appreciated.

Hi,

your custom code in GTM should contain a line like this

_paq.push(["enableLinkTracking"]);

or at least one with a “trackPageView” command.

Add the line you found above that (even below should not make a difference in that case AFAIK). And you are right: just replace the list in the second parameter with your desired file extension. If you want to add more than one extension, separate them with a |.

best,
Markus

Thank you for your reply.

Unfortunately, the custom HTML code (i.e. the piece of Javascript) doesn’t contain either. Here it is (with [CONTAINER_NAME] and [ID] censored):

<script type="text/javascript">
(function(window, document, dataLayerName, id) {
window[dataLayerName]=window[dataLayerName]||[],window[dataLayerName].push({start:(new Date).getTime(),event:"stg.start"});var scripts=document.getElementsByTagName('script')[0],tags=document.createElement('script');
function stgCreateCookie(a,b,c){var d="";if(c){var e=new Date;e.setTime(e.getTime()+24*c*60*60*1e3),d="; expires="+e.toUTCString();f="; SameSite=Strict"}document.cookie=a+"="+b+d+f+"; path=/"}
var isStgDebug=(window.location.href.match("stg_debug")||document.cookie.match("stg_debug"))&&!window.location.href.match("stg_disable_debug");stgCreateCookie("stg_debug",isStgDebug?1:"",isStgDebug?14:-1);
var qP=[];dataLayerName!=="dataLayer"&&qP.push("data_layer_name="+dataLayerName),isStgDebug&&qP.push("stg_debug");var qPString=qP.length>0?("?"+qP.join("&")):"";
tags.async=!0,tags.src="https://[CONTAINER_NAME].containers.piwik.pro/"+id+".js"+qPString,scripts.parentNode.insertBefore(tags,scripts);
!function(a,n,i){a[n]=a[n]||{};for(var c=0;c<i.length;c++)!function(i){a[n][i]=a[n][i]||{},a[n][i].api=a[n][i].api||function(){var a=[].slice.call(arguments,0);"string"==typeof a[0]&&window[dataLayerName].push({event:n+"."+i+":"+a[0],parameters:[].slice.call(arguments,1)})}}(i[c])}(window,"ppms",["tm","cm"]);
})(window, document, 'dataLayer', '[ID]');
</script>

Okay, that’s the full Piwik PRO tag manager code. Do you plan to implement tracking in both GTM and another tag manager? If so, you could keep it like it is and add another custom HTML as a clean-up tag (tag sequencing in GTM) for your existing tag that basically only contains the code line you found. That should work as well I guess.

Please try this:

<script type="text/javascript">
    var _paq = _paq || [];
    _paq.push(["addDownloadExtensions", "xz"]);
</script>

… and let me.know if that works for you (I do not have a similar set-up to test this).

As an alternative, you could use “just” the Piwik PRO tracking code. More info about that option can be found here: No Piwik PRO Tag Manager: install a tracking code | Piwik PRO help center

best,
Markus

1 Like

Worked like charm :slight_smile: I added this code as another custom tag and enabled sequencing so that this tag would fire before the main Piwik tag. It now successfully registers downloads of files with the xz extension, and all other downloads/goals are being registered well.

Thank you very much for your help!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.