Skip to content


Paypal tracking: Tracking API improvements & how to #2222

mattab opened this Issue · 13 comments

2 participants

Piwik Open Source Analytics member

See post in:,73977

I think we need to:

  • allow tracking by visitor ID, ie. the Tracking API should accept the visitor ID as a parameter, and use this to match the visitor (bypassing existing matching algorithm using IP etc)
  • JS API should have a getter for the referer cookie _pk_ref
  • Tracking API should have a parameter/new PiwikTracker function to set the referer for conversion attribution

Then we can also come up with a "How to" for tracking on Paypal. Of course these features will be useful for many other similar use cases.

Piwik Open Source Analytics member

(In [4350]) PiwikTracker

  • doc improvements
  • adding stubs for upcoming functionnality in Refs #2222
  • Refs #2172 will need a few new functions when this work is finalized (will ping you when new API is final)

I too would be very interested in this use case; I stumbled across the forum post looking for exactly this. This would be extremely useful for getting very accurate associations between referrals and actual purchases!

I think that (for at least this specific use case), you would need to make use of PayPal's custom field to pass the visitor ID through IPN (Since only PayPal, and not the actual visitor, will pass data through IPN)


Piwik Open Source Analytics member

(In [4369]) Refs #2222 Implementing Visitor ID forced request, so that we can log, after the fact, a page/goal/action to the latest visit of a given visitor ID (useful for example to trigger goal conversions that were missed by the JS beacon...)
Had to add another index on the log_visit table unfortunately, to ensure reasonnably fast lookup on the idvisitor, even though this index will very rarely get used (never if you don't use the tracking API with setVisitorId()...)

Piwik Open Source Analytics member

(In [4378]) Fixes #2168

  • Now crediting the right referrer for any goal conversion
  • Referrer URLs, timestamp, and Campaign name & keyword (parsed from the landing page URL) are now stored in a first party cookie (JSON encoded)
  • Added getters to the piwik.js to allow passing the values from the client, to store for later use in the PHP/Java Tracking API (paypal use case)
  • Added integration tests and basic JS tests

Refs #2172

  • Added a new API function: setAttributionInfo( $jsonEncoded ) which accepts JSON encoded array of 4 values (see implementation for details what to do with these values)
  • 2 new parameters are: _rcn and _rck to pass to piwik the campaign name and campaign keyword that will be creditted for the Goal conversion (if a goal is converted)
  • Also renamed setUrlReferer to setUrlReferrer -- Important that all public facing APIs use the proper writing

Refs #2222 Accurate Paypal tracking (or any other third party "after the fact" Goal conversion): implementation is now done, we must write some kind of guide and test

Piwik Open Source Analytics member

matheweis, I think you can now try and get this to work. Here is a proposal / pseudo code:

  • before user leave your site to go to Paypal, call the following JS functions:
    • visitorId = piwikTracker.getVisitorId();
    • attributionInfo = JSON2.stringify(piwikTracker.getAttributionInfo());
  • store these values in a database or similar
  • then when Paypal call you back via IPN
    • use the PHP Tracking API to record the conversion
    • you must call the following functions at least to credit the right visit with the right referrer information
    • $tracker->setVisitorId( $visitorId ); // which you stored earlier
    • $tracker->setAttributionInfo( $attributionJsonEncoded ); // which you stored earlier
    • $tracker->setTokenAuth( $your_superUser_token_auth ); // see
    • $tracker->doTrackGoal($idGoal, $revenue);

Then, Piwik will record, for the visit that was redirected to Paypal, the Goal conversion, making sure the Referrer (search engine, or website) or the Campaign (and keyword) used to reach the site in the first place, are credited for this goal conversion.

It would be great if you could give it a try and report if it is working :)

Piwik Open Source Analytics member

matheweis, now is a good time to help with the Paypal stuff if you can :) PLease see my post in the forum:,73977,page=1#msg-74946 and if you can test it and report, it would be great thanks!


After implementing this and running it for several days, I can confirm that it's working. Thanks Matt!

Piwik Open Source Analytics member

Thanks for your patience and help in getting this to work nicely!

Do you think you would be able to write a short, practical how to to get Paypal tracking work for other Piwik users? it would be great. I will then write a documentation about campaign tracking and to explain attribution in general.


Sure thing. I'll try to work on that this week.


Basic how to guide posted in forum: [,76296]

Piwik Open Source Analytics member

Thanks morrack, very appreciated! Maybe, we can wait a few weeks see if the post gets any feedback, and then turn it into some kind of official How to for ?

Piwik Open Source Analytics member

When we put this tutorial online as an "official doc", we could also write a section about "How to record recurrent payments / conversions using Piwik" which would explain how to track revenue from monthly memberships, and still credit the money to the initial referrer that brought in the visitor, credit the right keyword/country/etc.

Piwik Open Source Analytics member
@mattab mattab added this to the 1.x - Piwik 1.x 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.