Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#778 closed New feature (fixed)

add javascript API to trigger a goal trackGoal

Reported by: matt Owned by:
Priority: major Milestone: Piwik 0.4.1
Component: Core Keywords:
Cc: Sensitive:


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?

Change History (21)

comment:1 Changed 5 years ago by MarcLindsay

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.


comment:2 Changed 5 years ago by vipsoft (robocoder)

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:


comment:3 Changed 5 years ago by MarcLindsay

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

comment:4 Changed 5 years ago by MarcLindsay

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.


comment:5 Changed 5 years ago by vipsoft (robocoder)

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.

comment:6 Changed 5 years ago by MarcLindsay

Yep understood.

So.... :D

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

comment:7 Changed 5 years ago by matt (mattab)

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?

comment:8 Changed 5 years ago by vipsoft (robocoder)

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

comment:9 Changed 5 years ago by vipsoft (robocoder)



comment:10 Changed 5 years ago by MarcLindsay

Hey Vipsoft,

Is this ready to be tested out now?

Talk Soon

comment:11 Changed 5 years ago by matt (mattab)

(In [1214]) refs #778 adding the new Javascript Tracking API function: trackGoal to manually trigger a goal.
Example usage: piwikTracker.trackGoal(idgoal, [customRevenue], [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.

comment:12 Changed 5 years ago by matt (mattab)

you can download piwik with this function at

comment:13 Changed 5 years ago by vipsoft (robocoder)

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

comment:14 Changed 5 years ago by matt (mattab)

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 :-)

comment:15 Changed 5 years ago by MarcLindsay

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?)


comment:16 Changed 5 years ago by MarcLindsay

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.


comment:17 Changed 5 years ago by matt (mattab)

  • Summary changed from add javascript API to trigger a goal to add javascript API to trigger a goal trackGoal

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!

comment:18 Changed 5 years ago by MarcLindsay

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.


comment:19 Changed 5 years ago by matt (mattab)

  • Milestone changed from 1 - Piwik 0.4.2 to Piwik 0.4.1
  • Resolution set to fixed
  • Status changed from new to closed

seems to work fine - updated the doc on

comment:20 Changed 5 years ago by alivenk

comment:21 Changed 5 years ago by domtop

Note: See TracTickets for help on using tickets.