Complex cross site tracking


#1

We have a fairly complex tracking requirement involving goal tracking post WorldPay that we cannot get working in Piwik.

The scenario is this:
Referring site --> Our Site 1 --> Our Shop Site --> WorldPay --> post WorldPay aggregator on Our Site 2.

To make it simpler for development we’ve shortened this down to:
Referring site --> Our Site 1 --> post WorldPay dummy on Our Site 2.

When the referral arrives at Our Site 1 we set a custom variable using JavaScript. When we arrive post WorldPay we would like to check this custom variable and if set track a goal. We cannot get this working.

There is a complication. While Our Site 1 and Our Shop Site can use JavaScript the post WorldPay has to use the PiwikTracker.php API.

Our Site 1 is using the following JavaScript snippet:


<script type="text/javascript">
// < ![CDATA[   
var piwikBaseURL = (("https:" == document.location.protocol) ? "https://www.OurSite2.com/piwik/" : "http://www.OurSite2.com/piwik/" );
document.write(unescape("%3Cscript src='" + piwikBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E" ));
// ]]>
</script>
<script type="text/javascript">
// < ![CDATA[   
try 
{
var piwikLocalTracker = Piwik.getTracker(piwikBaseURL + "piwik.php", 9);
piwikLocalTracker.setCustomVariable(1, "visitOriginator", "DCBF", "visit" ) ;
piwikLocalTracker.trackPageView();
piwikLocalTracker.enableLinkTracking();
} 
catch( err ) {}
// ]]>
</script>

The post WorldPay script is using PiwikTracker thus:


 $dcbfPiwikTracker = new PiwikTracker(9);

 // Mandatory: set the URL being tracked
 $dcbfPiwikTracker->setUrl('http://OurSite2.com/post/postWorldPay.php' );

 $custVarVals = $dcbfPiwikTracker->getCustomVariable(1);
 if (($custVarVals[0] == "visitOriginator" ) && ($custVarVals[1] == "DCBF" ))
 {
   $dcbfPiwikTracker->doTrackGoal(1, $totalAmount);
 }

We were logging to file but for some reason that’s not being called by this process or it’s stopped working. But I’m happy to collect any debug info required. To be honest it makes my brain hurt getting my hear around this! Please can someone help?


#2

Forgot to mention that the Site ID 9 has all the URLs in it as described here http://forum.piwik.org/read.php?2,19781


#3

I’ve added worldpay.com as one of the sites into the Site with ID 9. Now the goal still isn’t being triggered but the link back form WorldPay is being shown as a Direct Entry but it’s not associated with the original referral entry. I’m guessing that’s because WorldPay don’t call the Javascript to carry the session on so Piwik simply thinks it’s from a new referrer.

Is there any way I can tell Piwik to pick up the session from where it left off. Or to allow a visit to WorldPay while not interrupting the current session?


(Matthieu Aubry) #4

Maybe Worldpay is similar use case to Paypal IPN? Check out the tutorial at: 301 Moved Permanently


#5

Thanks for this. I had tried setting the visitor id. All this seem to do was to set a variable inside the Piwik object called forcedVisitorId and nothing else. However, I hadn’t called setIp(…), setUrl(…) nor setUrlReferrer(…) so it’s worth trying those next, especially setUrlReferrer(…) which I can see may help join the halves together.

Also, when I called setTokenAuth(…) I got an error logged stating that the Auth Token was not 16 characters! It appears to be 32.