Goal tracking

We’ve just started with Piwik because Google Analytics doesn’t seem able to track events in the WorldPay callback scripts. When calling back to a site WorldPay doesn’t allow JavaScript nor it appears image tracking. It does however allow PHP calls to be made. We have a number of sites feeding into two shop sites. The WorldPay callback scripts are on just one of these shop sites. We want to be track visitors from specific landing pages with the goal set as a WorldPay callback with SUCCESS is a conversion.

Here is the code we use in the WorldPay callback script:
// – Piwik Tracking API init –
require_once “…/piwik/PiwikTracker.php”;
PiwikTracker::$URL = ‘oursite.com’;
$piwikTracker = new PiwikTracker(1);
// You can manually set the visitor details (resolution, time, plugins, etc.)
// See all other ->set* functions available in the PiwikTracker.php file
//$piwikTracker->setResolution(1600, 1400);

// Mandatory: set the URL being tracked
$piwikTracker->setUrl(‘oursite.com’ );

// Sends Tracker request via http
$piwikTracker->doTrackPageView(‘Oursite.com Post Worldpay’);

// You can also track Goal conversions
$piwikTracker->doTrackGoal(1, $totalAmount);
$piwikTracker->doTrackGoal(3, $totalAmount);
$piwikTracker->doTrackGoal(4, $totalAmount);

The call to doTrackPageView(…) appears to be working. The calls to doTrackGoal(…) appear to be not working. Although the goals in the Goals Overview page do have numbers they appear random! For example Goal 3 in the Goals Overview page has a count of 1, but in the database table piwik_log_conversion I see 9. So either 8 of these are not seen as valid conversions for some reason or the Goals Overview page is just not counting correctly.

I have loaded the code into NetBeans and with the PHP debugger I can see it going to PiwikTracker::sendRequest(…) but it never seems to get to core/Tracker/GoalManager.php. I’m not familiar with curl so I’m not sure how relevant the call to curl_exec in sendRequest(…) is. Moreover it never gets to set any Cookies since the cookie array is not empty.

I have configured Piwik to output debug information to a file and I can see lines like:
INSERT IGNORE INTO piwik_log_conversion (idvisit, idsite, idvisitor, server_time, location_country, location_continent, visitor_returning, visitor_days_since_first, visitor_days_since_order, visitor_count_visits, referer_type, referer_name, referer_keyword, referer_visit_server_date, idgoal, url, revenue, idaction_url, idlink_va, buster) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?), one for each call to doTrackGoal(…) .

I have many questions! For a start how does it manage to INSERT INTO piwik_log_conversion when apparently it doesn’t execute any code that actually does this. Is curl a messaging system? If so where is the message handler? Is there a way of expanding the VALUES so they don’t just appear as ‘?’ ?

But more important is why are the stats incorrect in the Goals Overview page??

Please be gentle, we are newbies!

Ok, so I’ve installed Piwik from scratch locally and am running the same scenarios locally.

Incidentally, I didn’t have adequate permissions on my database user. Rather than raising an error Piwik just fails silently. The database user needed permissions to create the archive tables. Piwik simply fell over and failed to display the Ecommerce and Goals page. I’m wondering if this something to do with the main error.

Have you solved your issue? what was the problem exactly?

:slight_smile:

Yes, by and large. The problems were me trying to get my head around analytics beyond just simply applying some Google supplied JavaScript, some issues with Piwik :slight_smile: and some fudging to get it all working! Naively I had assumed that the PHP API was just that, an API. I hadn’t cottoned on to how involved analytics are!

For reasons I won’t go into we have a somewhat complex web site setup. We want to be able to track visits and eCommerce goals in scenarios such as:
External site --> Landing page on site 1 --> shop site --> off to WorldPay --> back from WorldPay at post WorldPay aggregator site 3 !!

Although Piwik tracks visits very well through this maze we wanted to be able to track conversion goals. So each visitor is tracked all the way to the post WorldPay page, which is amazing and more than GA can manage :slight_smile: But you would have to sift through every visitor to see if the goal of external link --> conversion had been achieved. We tried setting up goals but they were never triggered. There were two issues:

  1. There is an issue in the PiwikTracker API when performing two actions one after the other. This includes tracking goals but also includes tracking a goal after a call to doTrackEcommerceOrder(…) as well. We were advised to set a different time stamp but found that a call to sleep(1) works just as well.
  2. Eventually I realised that every site entry is considered a new visit. It’s still a mystery to me how Piwik keeps track of the visit from external site all the way to post WorldPay, I think it must be using the visitor IP address in some way. I did manage to get the goal to trigger sometimes but then it caused Piwik to separate out the last step of the visit so the goals were now all seen as a single visitor in their own right!

So that’s were the fudging comes in. We can track goals within a reduced range of the entire visit. So we can use the landing page on site 1 to encode a link to the shop with pk_campaign and pk_keyword GET parameters encoded. Then, at checkout, we use the Piwik cookies and we pass these parameters into WorldPay. When WorldPay calls back we can examine these parameters and if appropriate trigger the goal. However, since we don’t fully understand how Piwik works we cannot encode the GET parameters into the link from the external site since there is no simple mechanism to carry them through from our site 1 to the shop. Moreover, if the user goes off exploring our site 1 and follows other links to the shop will these cookies will never be set?

We are sure there’s a better way to do this but we’re taking a step back in case we are no longer seeing the wood for the trees. Any advice you can give would be most welcome.

Thanks,
Owen

Owen, I’m not sure I understand everything here, but it sounds like Worldpay is maybe similar to Paypal IPN, check out the tutorial for more information: 301 Moved Permanently

Hello Matt,

I’m just following the PayPal IPN post at the moment and so far it’s going the way we want. I’m about to try using the Visitor ID part to tie the two halves together. This will achieve the part of tying visits to their post WorldPay conversion. This is done by setting up an auto goal to trigger on a visit to the post WorldPay script’s URL. In that post WP script we use the PiwikTracker PHP API as set out in the tutorial to try and tie it to the original visit.

The other part of the story is to trigger goals using the criteria of “the visit started at an affiliate web site X and ended up in a conversion on our web site”. Simples, I hear you cry, but the tracking gets lost in the maze of web site, detailed above, between affiliate X and our post WorldPay script. As WorldPay only supports one post script we need to differentiate between a conversion originated on our own sites and one started by a visit from an affiliate. I have tried using Piwik variables but these appear to get lost between sites, i.e. they are not carried across since the jump from site to site creates a new visitor. Well, I think that’s what’s happening. Using the Piwik Cookies is also only a partial solution. What we need is a Piwik variable that persists across multiple sites. Piwik must be doing something like this otherwise the jumps between the sites would appear as different blocks in the visitor logs. As I said I’m starting to not see the wood for the trees. Moreover we are using Wordpress and x-cart so modifying our sites underlying code could be painful, especially with x-cart!

the visit started at an affiliate web site X and ended up in a conversion on our web site

This is what is achieved via get/setAttributionInfo() → you can then see conversion rate/conversions/revenue for each website URL, or for direct entries, etc.

I’m just following the PayPal IPN post at the moment and so far it’s going the way we want. I’m about to try using the Visitor ID part to tie the two halves together. This will achieve the part of tying visits to their post WorldPay conversion. This is done by setting up an auto goal to trigger on a visit to the post WorldPay script’s URL. In that post WP script we use the PiwikTracker PHP API as set out in the tutorial to try and tie it to the original visit.

The other part of the story is to trigger goal using the criteria of “the visit started at an affiliate web site X and ended up in a conversion on our web site”. Simples, I hear you cry, but the tracking gets lost in the maze of web site, detailed above, between affiliate X and our post WorldPay script.