Here’s the rub: to have real value, I need to associate these goals with the keyword/campaign/referrer that sent the visitors to me in the first place. Here’s what I’m thinking should be possible. From my website, just before the user clicks the button to go pay on paypal’s website, I could grab some sort of value (visitorID?) and pop it into a custom variable that paypal would return to me when it calls my IPN script. I could then send that back to Piwik when I trigger the goal via the PiwikTracker.php script. I’m just not certain what value I should grab to passthru to my IPN script, and then what I should add to the PiwikTracker call to make the association between original visitor and the goal.
I’ve searched the forum carefully before posting this - quite surprised that nobody else has raised this issue before. Hopefully this should be an easy one for some of you Piwik guru’s out there. Any help will be very much appreciated!
What is the solution that GA proposes that works 20% of the time?
Piwik attributes conversions to a Keyword or website or campaign, based on the value in the First party cookie “_pk_ref.*****”. This cookie is set with the referer used to reach the site.
Problem is when you trigger conversion on paypal, you don’t have the 1st party cookies available.
trigger the Goal on your website so that this cookie is passed succesfuly to Piwik. (I guess you trigger it on Paypal to ensure that all conversions are tracked, in case users close the paypal site before coming back to your site?)
we could pass the Referers (found in the cookie) to Paypal (somehow? not sure what is possible there), and then we could pass the referer to the PHP tracking image. I don’t think we can do that currently, but that should be easy to add.
Let me know. In any case, we would really want to help you here and make sure Piwik works in this use case, because as you point out, it’s a very important use case.
Hey Matt, I really appreciate your willingness to make this happen!
Paypal in a nutshell:
1 - order page on my site with a paypal button (html form). I can embed custom variables into this form that paypal will pass back to my IPN script, so if I can obtain the visitor ID at this point and turn it into a variable, I can get that info back at the critical point.
2 - On submitting the form, the user is redirected to paypal.com to complete the sale
3 - User see’s a thank you page on paypal.com, and may or may not (80% of the time will not) then carry on to end up on a thank you page back at my site. GA’s “solution” is to trigger the goal on this thank you page on my site. That’s why I say it only works 20% of the time.
If this can happen it would be a true solution, since paypal will keep hitting my IPN script until it see’s a proper response. Thus, 100% of the sales should get properly tracked.
I know enough php to be dangerous, but don’t consider myself a true developer. If however there is anything I can do to assist with getting this feature added (testing?) I would be more than happy.
but currently the Tracking API does not accept the visitor ID like it does accept the visitor IP.
Currently, there is no JS helper function to fetch this referer value (stored in a first party cookie), but we could easily add it.
Also, there is no currently a way to pass this referer value to the Tracking API, but again we could add it easily as well.
So the missing pieces in Piwik are at least:
pass the referer to Piwik via tracking API (new Tracking API parameter & new function in PiwikTracker PHP class)
What is the current code snippet you use to trigger the conversion in the IPN script?
1 - Being totally new to piwik in general it took me quite some time (and a few false starts) to figure out where to get the latest beta files so I could try your improvements out. I think I got my site upgraded properly to 1.2.5rc8, but on my goals tab I get an error (Undefined index: allow_multiple in path/to/piwik/plugins/Goals/Controller.php on line 136). Did I defeat myself before I even got started? Should I post the full backtrace?
Update: since I only have a couple weeks of data in piwik and still have GA running for now, I reinstalled from scratch. So, disregard my first point above about the db troubles, that is resolved. Still don’t seem to be getting any data in the visitorID and attributionInfo variables though, not sure what I’m doing wrong…?
Don’t worry it is pretty complicated stuff and I didn’t explain properly
The code you pasted above, is the first part of the problem: it is getting the values from Piwik, about the visit, before it is leaving your site to Paypal.
Now there must be a way, that Paypal will somehow contact your site later on (this is the IPN script I think?).
Then, when Paypal contacts you, you will want to execute a PHP Script that will track the Goal conversion for this visit.
To do so, the php script executed when paypal contacts you after the sale was done, will use the Tracking API and look something like:
PiwikTracker::$URL = 'http://www.example.org/piwik/';
$t = new PiwikTracker( $idSite = 1 );
// If you want to force the visitor IP, or force the server date time to a date in the past,
// it is required to authenticate the Tracking request by calling setTokenAuth with the Super User token_auth
$t->setTokenAuth( $token_auth );
$t->setVisitorId( $visitorId );
$t->setAttributionInfo( $attributionJsonEncoded );
// Track the goal with the revenue
$t->doTrackGoal( $idGoal = 1, $revenue);
As you see, to run this script you will need few information:
your super user token_auth, Piwik URL, Piwik idSite, and idGoal for your “Paypal order” goal
the $visitorId (which is the value that you put in your jsCustom variable - how can you get it back when this script runs?)
the $attributionInfo (same as $visitorId, you must get this value when Paypal contacts you back)
the $revenue that Paypal will also give you
I don’t know how you can get the data back from Paypal but hopefully you can find the information. If you are really lost I could do some research. Let us know how it goes!
I’ll send you some additional troubleshooting details in a PM.
I had some document.write statements to help debug, apparently they were creating problems. Thanks to some help from Matt in a PM thread, step 1 is now working properly for me. I’ll give step 2 a go this evening (expect it to work fine) and let everyone know.
Ok, I’m misunderstanding something about the whole setTokenAuth thing. I had no trouble passing my variables to paypal and getting them back again, then seperating them out (had my script email them to me seperately to be sure, got exactly what I expected). However, the goal tracking is not working as expected. While trying to debug, I discovered that if my doTrackGoal statement was BEFORE my setTokenAuth, then at least a goal would be registered (although not properly attributed). However, if I moved my doTrackGoal statement to AFTER my setTokenAuth, then nothing worked. I’m pretty sure I have the right token (top of my page, clicked API). I even tried changing my password to force a new token, then tested with that and got the same results. I suspect once I can get properly authenticated as super-user then this puppy should work. Here’s my code:
// -- Piwik Tracking API init --
PiwikTracker::$URL = 'http://mysite.com/piwik/';
echo("Testing. Custom: ");
$temp = $_POST['custom'];
echo($temp); // french or spanish & [affiliate code] & ip & visitorId & attributionInfo
list($custom, $affCode, $custIP, $visitorId, $attributionInfo) = explode("&", $temp);
list($affID, $prodID) = explode(":", $affCode);
$piwikTracker = new PiwikTracker( $idSite = 1 );
$piwikTracker->setTokenAuth("my token from API section of piwik install");
//$piwikTracker->setCustomVariable (2, 'testIP', $custIP);
$piwikTracker->doTrackGoal($idGoal = 1, $revenue = 25);
$piwikTracker->doTrackPageView('Display paypal post details');
Note that the above code is from a test page I put together to skip the hassle of going through paypal, since I’ve already verified that part will work fine.
I’m running five campaigns in same time but campaign goal count is zero although conversions are recorded in database. The problem is that Piwik identifies thous conversions as website goals (‘referer_type’ in piwik_log_conversion table is set to 3 instead 6 as i mentioned in post before) instead of campaign goals. As you can see on attached screenshot (attach_1.png), goal segmentation table shows strange results where campaign with zero visits shows conversion ratio higher than null which is obviously incorrect value. Meanwhile website conversions split table (attach_2.png) shows conversions of campaigns (referrer is of campaign site), again with strange visit count.
thank you for fast answer but it is still not solving my problem. I’m 100% sure that conversions from campaigns were there (I can see them in database table) but are not shown in segmentation report. Here is my “Conversions segmentation report” taken from UI (I’m omitting figures like conversion rate and so):
-------------------------- visits - conversions-
Search Engines 480 3
Direct Entry 160 6
Campaigns 110 0
Websites 39 7
And report should be:
-------------------------- visits - conversions-
Search Engines 480 3
Direct Entry 160 6
Campaigns 110 3
Websites 39 4
Again, some of conversions recorder as “Website conversions” should be recorded as “Campaign conversion”. In this case 3 conversions.