Goal tracking via class in link



is it possible to trach goals in the same way as tracking downloads (by putting class=“piwik_download” in tag) ?


(Matthieu Aubry) #2

No, but you can use piwikTracker.trackGoal( goalID );


i have tried putting onClick=“piwikTracker.trackGoal( goalID );” in but I got “piwikTracker undefined”. I have to track goal when the user clicks the link. Im not able to put any javascript in to the page of that link becouse I have there only a 302 redirect.


You have to initialise the piwikTracker before you can use it. Put something like the following in your html markup (e.g. the head section):

<script type="text/javascript">
    var pkBaseURL = (("https:" == document.location.protocol) ? "https://www.yourdomain.com/piwik/" : "http://www.yourdomain.com/piwik/");
    document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
<script type="text/javascript">
    try {
        var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);
    catch( err ) {}

Don’t forget to change the url and to replace “1” by your Piwik website ID.


is there any other way to achieve this ?


It might be easier to help if you describe in more detail why this is no option for you :slight_smile:

There is also an option to do the tracking on the server side via the php tracker. See Tracking API - Analytics Platform - Matomo.


i just prefer to “hide” piwiks code at the bottom of the page source code :wink:

will server side tracking recognise the user (his visit history on the site) ?