CVM / Magento_GoogleTagManager

Google Tag Manager extension for Magento
67 stars 55 forks source link

Pls add incrementalVisitorLifetimeValue dataLayer value - as visitorLifetimeValue is not usable #17

Closed phildpearce closed 10 years ago

phildpearce commented 10 years ago

This issue is NOT related to the visitorLifetimeValue logic for logged-in customers: https://github.com/CVM/Magento_GoogleTagManager/commit/3d601812231e81bf951771a151df8df594831ba6

Background:This is not specifically an issue with your plugin, but is a function of how GA works. However, your plugin could be used to fix this, so that a JS macro patch is not needed and the implementation is simplified.

Issue: For returning customers... GA event integer (and/or GA custom metric) is BLENDING the previous visitorLifetimeValue PLUS new order visitorLifetimeValue.

Hence visitorLifetimeValue is severely inflated for returning customers.

Thus, I had to add script to patch the logic in GTM to create an incrementalVisitorLifetimeValue variable. But it would be much cleaner if this existed on as a dataLayer variable instead.

For example:

  1. first order = £100 transaction and £100 visitorLifetimeValue (visitorLifetimeValue = £100)
  2. second order = £100 transaction and £200 visitorLifetimeValue (incrementalVisitorLifetimeValue = £100 ADD previous visitorLifetimeValue = £100)
  3. third order = £100 transaction and £300 visitorLifetimeValue (incrementalVisitorLifetimeValue = £100 ADD previous visitorLifetimeValue = £200)

// jsmacro_user_cm002_currencyType_incrementalVisitorLifetimeValue function() { If ( {{js_window.universal_variable.user.returning}} = false; ) { var incrementalVisitorLifetimeValue = {{js_window.dataLayer.visitorLifetimeValue}}; // e.g. £100 return incrementalVisitorLifetimeValue; } else { var incrementalVisitorLifetimeValue = {{js_window.dataLayer.visitorLifetimeValue}} - {{dl_transactionTotal}}; // e.g. £100 - £200 = £100 incremental return incrementalVisitorLifetimeValue; } }

CVM commented 10 years ago

Given that this value is incremental, does the transactionTotal on the order success page not already give you the value you need?

phildpearce commented 10 years ago

Re: transactionTotal does not provide what I need (unless I use a JS macro that I mentioned above).

Is its OK, for new customer. Where incrementalVisitorLifetimeValue = transactionTotal

But it does NOT work for, existing customer where incrementalVisitorLifetimeValue = visitorLifetimeValue - transactionTotal

CVM commented 10 years ago

The use of the term "incremental" suggested to me it was more of a counter. It sounds like what you're after is more of a previousVisitorLifetimeValue (i.e. the visitorLifetimeValue before the most recent transaction occurred).

Based on this logic, for guests the previousVisitorLifetimeValue would always be 0 - setting it to the transactionTotal actually appears incorrect? At the very least, why it is different would not be clear to anyone else using the extension.

Similar to some of the other issues you've raised, this does seem very closely tied to specific functionality that you wish to implement for yourself, rather than a more general feature most users would find useful. Simply using the visitorLifetimeValue as a custom metric to segment on visitors worth X over a specified timeframe is a more likely use case.

For this reason, I won't be putting this in the extension. But if you want to go ahead with this anyway, you're welcome to fork the repo and make changes similar to what's below (from app/code/community/CVM/GoogleTagManager/Block/Gtm.php).

Existing code:

if ($customer->isLoggedIn()) {
  $data['visitorLifetimeValue'] = round($ordersTotal,2);
} else {
  $orderData = $this->_getTransactionData();
  if (!empty($orderData)) {
    $data['visitorLifetimeValue'] = $orderData['transactionTotal'];
  } else {
    $data['visitorLifetimeValue'] = 0;
  }
}

Revised code:

$orderData = $this->_getTransactionData();
if ($customer->isLoggedIn()) {
  $data['visitorLifetimeValue'] = round($ordersTotal,2);
} else {
  if (!empty($orderData)) {
    $data['visitorLifetimeValue'] = $orderData['transactionTotal'];
  } else {
    $data['visitorLifetimeValue'] = 0;
  }
}
if ($ordersTotal > 0) {
  $data['previousVisitorLifetimeValue'] = $ordersTotal - $orderData['transactionTotal'];
}
else {
  $data['previousVisitorLifetimeValue'] = 0;
}

But if you have a working solution based on a GTM JavaScript macro, I'd probably stick to this if it's working. No sense reinventing the wheel!

phildpearce commented 10 years ago

previousVisitorLifetimeValue is probably a better name.

Thanks for the example code, I'll ask the Magento developers if they have an appetite for forking this

I need to tweak the JS macro, but once working I'll post it here aswell.

Thanks!

Sent from my iPhone

On 10 Apr 2014, at 14:23, Chris Martin notifications@github.com wrote:

The use of the term "incremental" suggested to me it was more of a counter. It sounds like what you're after is more of a previousVisitorLifetimeValue (i.e. the visitorLifetimeValue before the most recent transaction occurred).

Based on this logic, for guests the previousVisitorLifetimeValue would always be 0 - setting it to the transactionTotal actually appears incorrect? At the very least, why it is different would not be clear to anyone else using the extension.

Similar to some of the other issues you've raised, this does seem very closely tied to specific functionality that you wish to implement for yourself, rather than a more general feature most users would find useful. Simply using the visitorLifetimeValue as a custom metric to segment on visitors worth X over a specified timeframe is a more likely use case.

For this reason, I won't be putting this in the extension. But if you want to go ahead with this anyway, you're welcome to fork the repo and make changes similar to what's below (from app/code/community/CVM/GoogleTagManager/Block/Gtm.php).

Existing code:

if ($customer->isLoggedIn()) { $data['visitorLifetimeValue'] = round($ordersTotal,2);} else { $orderData = $this->_getTransactionData(); if (!empty($orderData)) { $data['visitorLifetimeValue'] = $orderData['transactionTotal']; } else { $data['visitorLifetimeValue'] = 0; }}

Revised code:

$orderData = $this->_getTransactionData();if ($customer->isLoggedIn()) { $data['visitorLifetimeValue'] = round($ordersTotal,2);} else { if (!empty($orderData)) { $data['visitorLifetimeValue'] = $orderData['transactionTotal']; } else { $data['visitorLifetimeValue'] = 0; }}if ($ordersTotal > 0) { $data['previousVisitorLifetimeValue'] = $ordersTotal - $orderData['transactionTotal'];}else { $data['previousVisitorLifetimeValue'] = 0;}

But if you have a working solution based on a GTM JavaScript macro, I'd probably stick to this if it's working. No sense reinventing the wheel!

Reply to this email directly or view it on GitHubhttps://github.com/CVM/Magento_GoogleTagManager/issues/17#issuecomment-40080030 .