Skip to content


add javascript API to trigger a goal trackGoal #778

mattab opened this Issue · 19 comments

3 participants

Piwik Open Source Analytics member

This is the highest priority task to make Goal Tracking really useful; I was thinking of:```
piwikTracker.recordGoal( idGoal, customRevenue, customVars );

This requires, I believe, some minor updates to core/Tracker/*.php to set a new request type. 

Any other feedback?

I think this will do well for Goals initially to get a basic functionality that lets us compete with and give my clients good advice on moving away from other platforms.

How do you imagine the customVars being handled (is that to say add in different options of the sale much like I showed you would we could track inside skype?)

I assume from looking at the referrer functions that the goals etc will also track to Search engines & keywords, direct traffic etc etc.

being that it will also now be in the tracker means it can also be used on dynamic url's etc right, not limited to finding a url for goal conversion.



Keeping it simple, given the flexibility of customVars, I don't think we need separate customRevenue and customVars parameters.

Thus, the request from the client resembles those recorded for outlinks and downloads:


I tend to agree.

Doing what you mentiong there Vip, would then let something like this data be tracked also?

First Name
Last Name
Date & Time of Booking
Confirmation No
Car Class (ECMR, SCAR etc)
Pickup Location
Dropoff Location
Pickup Date & Time
Dropoff Date & Time
Supplier (Europcar, Thrifty etc)
Total Booking Amount
Flight No

Assuming I could get all that data in a sale process (which I do post through)?

Talk Soon


of course the only extra thing to say on that is....

so long as within customVars you can set the normal revenue that the current goal tracking uses (so that it can use the revenue as it would normally in the system.



The idea here is that if you omit the custom revenue in customVars, Piwik should fallback to using the revenue configured for that goal.

Example JavaScript:

  var myGoal = { 'FirstName' : 'Anthon' };
  myGoal.LastName = 'Pang';
  myGoal['revenue'] = 10; // override

This is JSON stringified to:


Note: the custom data isn't being logged yet.


Yep understood.

So.... :D

ETA on logging of revenue at tracker level :D One very excited tester eh

Piwik Open Source Analytics member

I agree that we could put the revenue in the customVars, but because revenue is the only "custom var" that is built-in the plugin - and will always be - I thought it would be clearer / easier to put it in the function signature. It would be optional though. For consistency we could rename it actually:```

piwikTracker.trackGoal( idGoal, [customRevenue], [customVars]);

does it make sense?

(In [1206]) refs #778 - implement trackGoal() on client-side




Hey Vipsoft,

Is this ready to be tested out now?

Talk Soon

Piwik Open Source Analytics member

(In [1214]) refs #778 adding the new Javascript Tracking API function: trackGoal to manually trigger a goal.
Example usage: piwikTracker.trackGoal(idgoal, [customData);

This can be used on external websites, simply give them the Piwik JS tracking tag, remove trackPageView and enableLinkTracking, and add the trackGoal call.

Marc, please let us know if you need more details to write the tutorial/documentation.

Piwik Open Source Analytics member

you can download piwik with this function at


(In [1216]) refs #778 - fix broken unit test and de-lint

Piwik Open Source Analytics member

the author of a book about Joomla and Virtuemart (ecommerce for Joomla) contacted us, and let us know that she would like to have a chapter about Piwik in the book, as well as documentation on how to track ecommerce using the goal tracking plugin, and the newly created trackGoal method - let's keep this in mind.

Marc, a simple ecommerce example would be great to have in the documentation use cases :-)


Appears that in the changes done in rc1 the old tracker code being generated has been put in place (under show code for the sites)


Also when would they need that chapter in mind?

Also. Would it be possible to log both the original referrer that had the goal converted, and also the last one (I know you can set it in the settings file to be one or the other, but how about an option for both?)



Unable to get the goal to track currently you can see live example of code on

the site ID & goal ID are correct.

Unsure how to make this track as you must also set a tracking url when setting the goal up (no option yet to say use in code tracking only, would be good to add that).

Would this be throwing it off?

Will try catch up with someone in the morning and give it another shot.


Piwik Open Source Analytics member

Marc, shame on me, my link the release was wrong (I pointed to 0.4rc1 instead of 0.4.1-rc1)... here is the right link:

sorry for the inconvenience, let me know how it goes!


From initial checks its looking good on one domain.

Will roll it out over some more tomorrow.

though strange thing happened the updates Matt have stopped SearchEnginePosition plugin working.


Piwik Open Source Analytics member

seems to work fine - updated the doc on

@mattab mattab added this to the Piwik 0.4.1 milestone
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.