0

-- 2019/07/08 Edit: Add event variable, trigger setting --

  1. I set a DataLayer Variable called {{SP_sale_event}} to get "my_event", and set to version 2.
  2. Trigger is when page goes to "checkout" page, the end of purchase flow, AKA "thank you" page.
  3. Set a Universal GA Tag, set Label to {{SP_sale_event}} .

-- Original message --

I had set some datalayer in checkout page like :

<script type="text/javascript">
dataLayer.push
({
  'event': 'checkout',
  'ecommerce': {
    'purchase':{
      'actionField':
        {
          'id': "<%=order.ID%>",
          "affiliation": "Online Store",
          "revenue": "<%=order.price%>"
        }
      }
    }
});

$(window).load(function()
{
/**
* checkout data for GTM
*/
window.dataLayer = window.dataLayer || []
dataLayer.push
({
    "transactionId":"<%=order.ID%>",
    "transactionAffiliation":"My Online store",
    "transactionTotal":"<%=order.price%>",
    "transactionTax":"0",
    "transactionShipping":"0",
    "transactionProducts":
    [
    //some code about order detail ...
    ]
});
});
</script>

<script type="text/javascript">
  dataLayer.push({
  'my_event':'Sale event, purchased in <%=order.date%>, price: <%=order.price%>, orderID: <%=order.ID%>, member: <%=(order.isNew)?"New register":"old member"%>』'
  });
</script>

And set a tag on GTM to capture Label "my_event".

However, in GA's event report, much event didn't comes with valid Label, but instead with (not set).

For example, I get 23 "my_event" in GA report, but there are only 3 events comes with Label Sale event, purchased in ..., other 20 events are been collected in a (not set) group.

So my setting did works sometime, but most time didn't.

How do I trace and fix this ?

RRTW
  • 3,160
  • 1
  • 35
  • 54

1 Answers1

0

The problem is, that when you push the relevant data (my_event) into dataLayer, you do not add an actual event to it, that could trigger a proper tag to run, and send your data. Most likely it happens, that if my_event gets pushed into the dataLayer before your tag runs, it gets sent. So there could be several solutions for this, based on your desired outcome.

You could merge for example your two dataLayer calls, especially, if these are related, and the data is available at this point:

dataLayer.push
({
  'event': 'checkout',
  'ecommerce': {
    'purchase':{
      'actionField':
        {
          'id': "<%=order.ID%>",
          "affiliation": "Online Store",
          "revenue": "<%=order.price%>"
        }
      }
    },
  'my_event':'Sale event, purchased in <%=order.date%>, price: <%=order.price%>, orderID: <%=order.ID%>, member: <%=(order.isNew)?"New register":"old member"%>』'
});

An other solution would be to specify the event with your my_event variable, and set the firing trigger to match this event name, e.g.:

dataLayer.push({
  'event':'send_my_event',
  'my_event':'Sale event, purchased in <%=order.date%>, price: <%=order.price%>, orderID: <%=order.ID%>, member: <%=(order.isNew)?"New register":"old member"%>』'
  });

It might also work to leave your code as-is, and send the data on Window Loaded event, where all other scripts are ready, but this might not be as reliable, as the versions, where you explicitly send the data and triggering event together.

kgrg
  • 1,605
  • 1
  • 12
  • 14