Opened 3 years ago

Closed 3 years ago

Last modified 16 months ago

#2564 closed Bug (fixed)

Custom variables not always set in the conversion when using tracking API

Reported by: gordo Owned by:
Priority: critical Milestone: 1.12.x - Piwik 1.12.x
Component: Core Keywords: ecommerce, browser, goal, tracking, database
Cc: Sensitive: no

Description (last modified by matt)

I checked the database and have confirmed that custom vars are not being set in the log_conversion table but are being set in log_visit.

I'm using the PHP API instead of Javascript if that helps narrow things down at all.. I haven't dug into the core code much at all, so I'm not sure really how the log_conversion custom vars are being added/updated.

I have tried using both visit and page scoped vars as well...

My code goes something like this:

$piwikTracker->setCustomVariable($id = 1, $name = "Browser Version", $value = $this->agent->browser().' '.$this->agent->version(), $scope = 'visit');
$piwikTracker->doTrackPageView('Home');

Maybe there's a better way to track goal conversion rates by browser version?

Google Analytics does this, so I assumed Piwik would, but I'm not finding any way to do this and found this issue w/ custom vars. We'd like to use custom vars to segment our split-test variations as well, and if they aren't tracking conversions at all then Piwik is useless for us.

http://node.gordo4.com/snaps/5ede0a39df3b8354dc5d70af8f2d24a6.png
vs
http://node.gordo4.com/snaps/b2d5c80eb56ceefd9e4fc1a9a09c95de.png

This is a fresh install of 1.5.1, not an upgrade, so I'm at a loss here as to why it's not working. We get a boatload of traffic, so I'm using a cron to do the archiving. The only thing I've changed was added memory_limit 4G to the PHP commands in the cron script.

Change History (13)

comment:1 in reply to: ↑ description Changed 3 years ago by gordo

Also: http://node.gordo4.com/snaps/a327819fb2d14ffb093e169c1b4f69f4.png

I'm assuming Other, are all of the IE versions and Opera and such. Not sure why those are all meshing into Other when they have more keywords and all of the Firefox variations are shown independently, but that's beside the point of this ticket.

comment:2 Changed 3 years ago by matt (mattab)

  • Description modified (diff)
  • Milestone set to 1.6 Piwik 1.6

Thanks for the report. As you can see on the demo it is working fine at least for us.

You are right that Piwik doesn't process conversion rates per browser. We process it for Countries/Custom vars/Websites/Keywords/etc. but not all user attributes (for performance reasons). Using Custom vars is therefore a good idea if you wish to achieve this.

The sub tables are limited to 50 by default (see faq). you can change this to a bigger value by overriding datatable_archiving_maximum_rows_subtable_referers in your config.ini.php (which also happens to affect custom vars subtable, not only referer - yes this is confusing ;)

log_conversion custom vars are normally copied from the log_visit table indeed. Would you be able to submit a small code using php tracking api, that would help reproduce the problem? thanks

comment:3 Changed 3 years ago by gordo

On our landing page I'm calling the following to set the browser version into a custom var:

if(! $this->agent->is_robot() ){
	require_once APPPATH."libraries/PiwikTracker.php";
	PiwikTracker::$URL = 'http://xxxx.xxxx.com/analytics/';
	$piwikTracker = new PiwikTracker($idSite = 1);
	$piwikTracker->setTokenAuth('xxxxxxxxxxxxxx');
	$piwikTracker->setIp($_SERVER['REMOTE_ADDR']);
	$piwikTracker->setCustomVariable($id = 1, $name = "Browser Version", $value = $this->agent->browser().' '.$this->agent->version(), $scope = 'visit');
	$piwikTracker->doTrackPageView('Home');
}

At the top of our process_order function I'm calling:

require_once APPPATH."libraries/PiwikTracker.php";
PiwikTracker::$URL = 'http://xxxx.xxxx.com/analytics/';
$piwikTracker = new PiwikTracker($idSite = 1);
$piwikTracker->setTokenAuth('xxxxxxxxxxxxxxxxxxxx');
$piwikTracker->setIp($_SERVER['REMOTE_ADDR']);

Before we attempt to process the order I run the following so we can track abandoned carts" (due to things such as CC error, etc) Basically our process_order only gets ran when the user submits our registration form. Sometimes we lose orders for various reasons, such as duplicate email, invalid CC, etc...

$piwikTracker->addEcommerceItem($sku = $order_data['product_sku'], $name = $order_data['product_name'], NULL, $price = $order_data['product_charge_now'], $quantity = 1);
$piwikTracker->doTrackEcommerceCartUpdate($grandTotal = $order_data['product_charge_now']);

Then after we actually process the card successfully we redirect to a receipt page, right before that happens I run the following:

$piwikTracker->addEcommerceItem($sku = $order_data['product_sku'], $name = $order_data['product_name'], NULL, $price = $order_data['product_charge_now'], $quantity = 1);
$piwikTracker->doTrackEcommerceOrder($orderId = $tracking_data['order_id'], $grandTotal = $order_data['product_charge_now']);

There are more examples, such as duplicate order, how we log the CC_Errors, etc... but those don't apply to this ticket and all appear to work properly.

Like I said before, the custom vars are tracking properly, but they aren't updating into the conversions table. Do I need to re-set those variables again on the conversion? I would assume the values would be copied out of the visits table upon conversion...

comment:4 Changed 3 years ago by gordo

Any advice?

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

gordo, it would really help if you were able to produce a script that reproduces the issue on a fresh piwik install.

Are you able to test a simple version of your script that will show the issue?

we hope to fix this bug for Piwik 1.6 for sure, your help is greatly appreciated.

thanks!

comment:6 Changed 3 years ago by gordo

When I get a free moment I'll setup Piwik on one of my other domains and see if I can replicate the issue and will provide access if need be.

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

gordo, do you have an update on the issue? would be great to get this bug fixed in next release :) thanks

comment:8 Changed 3 years ago by matt (mattab)

  • Milestone changed from 1.7 Piwik 1.7 to 1.6 Piwik 1.6

comment:9 Changed 3 years ago by matt (mattab)

  • Resolution set to wontfix
  • Status changed from new to closed

Thanks for the report. I could replicate the bug. This is because the custom variables, during a conversion, are read from the first party cookie supposedly passed to the request. We could change the code to read custom variables from the visit and set them in the conversion, but this would add overhead for all requests.

Therefore in this case we won't fix (for now, might re-consider later), and to work around this limitation please set the custom variables again before making the purchase / conversion.

comment:10 Changed 3 years ago by matt (mattab)

  • Milestone changed from 1.6 Piwik 1.6 to 1.7 Piwik 1.7
  • Resolution wontfix deleted
  • Status changed from closed to reopened

Well it's not a wontfix, since I now confirm that it should be copied into conversions, sorry for the comment above ;)

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

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [5251]) Fixes #2564 - now copying custom variables from the visit when custom variables not passed in the Goal conversion (or ecommerce) tracking request (eg. when request comes from a script in the backoffice)

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

  • Summary changed from Custom Var / Browser Goal Tracking (Ecommerce) 1.5.1 to Custom variables not always set in the conversion when using tracking API

comment:13 Changed 16 months ago by matt (mattab)

  • Milestone changed from 1.8.x Piwik 1.8.x to 1.9.x - Piwik 1.9.x

Milestone 1.8.x Piwik 1.8.x deleted

Note: See TracTickets for help on using tickets.