Ecommerce order tag not working

Hello,

One of our clients has a site where an ecommerce dataLayer was already integrated. I adapted the ecommerce tags and all of them are working fine: “product detail view”, “add to cart” and “remove from cart”.

However, the order tag seems to not work: I did several tests and each time, my session ends up with an abandoned cart and no order.

Here’s the dataLayer event that is pushed when the order is confirmed:

And here is my ecommerce order tag:


I trigger this tag when the dataLayer event “arguments.purchase” occurs. I can see my tag being fired when debugging, so no problem with the trigger.

Also, I tried deleting the double curly braces from the order information properties (for example, turning “{{ transaction_id }}” into “transaction_id”), but the result is the same.

What am I missing? I can share the website link in private if necessary.

Thank you!

Hi,
This seems like an issue with parsing the correct value in case of the transaction_id object.

You might want to take a look at this thread:

Thank you Adam, this thread is indeed what I needed!

I used a custom JS variable to turn “transaction_id” into a string. This was for sure the reason it didn’t work.

I still have a doubt though: in my case, the “id” and “variant” objects of the items are also numbers while your documentation says these must be strings:

Do I have to turn these into strings with custom JS variables too? And by the way, use these variables in the product mapping fields of the tag?

Yes, you will have to turn these into strings as well preferably with a custom JS variable and apply the required type of a value into your ecom setup.

This is a known problem and I will create a future request to facilitate adding different types of values into these ecom tags.

Adam,

I think I might have another issue then, as my dataLayer variable won’t return the ID…

Here is the variable definition:

I first need this variable to work before converting it into a string with a JS variable. Did I write it wrong? If needed, I can send you the website link in private and tell you how to make test orders.

Also, I’m wondering how this variable would behave for orders that have multiple distinct products (= multiple IDs)?

Thank you again

// EDIT
I found out why the variable isn’t working: it’s because items is an array. I would need to write distinct variables “items[0].id”, “items[1].id”, etc. to get the ID of each individual ordered product…

However, using this custom JS variable, I was able to get each ID in an array:

Here is the result for single product orders:
image
And for multiple products orders:
image

Now, my question is: do I still have to convert this array of IDs into a string via a JS variable? If so, would the following function be correct?

function() {
  return String({{ JS get array items.id }});
}

In debug, it returns “productID1,productID2” when there are multiple distinct products in the order:
image

However, it simply returns productID1 (without quotation marks) when there is a single product:
image

Would this be working in the product mapping “SKU” field of the tag?

The function that you brought up would be correct. If you are not sure if your variable type matches the requirements then you could also add to the function that changes the type of a variable a console.log(typeof {{ your variable }});. This way you could check if the correct type has been applied to your variable value.

Also, it sometimes happens that these values are captured by Piwik PRO without the qutation marks. Here is my example:

So, what I essentially did is I pushed an addToCart event to the dataLayer and then tried to capture the id, which from the beginning was a string type variable as seen in the browser’s console, with a “ecom var” variable in Piwik PRO. As you can see even though the type is string the debugger caught it without the quotation marks.

To make sure that everything works properly try to set up a test ecom tag that would caputre the modified value from your variable and then generate an ecommerce action. If there are any issue in the tracker debugger, then there is a high chance that the variable is not working properly.

Thank you Adam,

I just did a test order using the variables to turn id and variant objects into strings:
image

Here is the tag config:

I’ll check in the coming hours if it worked and tell you, but I have a doubt for 2 reasons:

  1. In the debugger, an error appears at the end of the ecommerce order tag:
    image

  2. In the “Network” tab, when I click on the “ppms.php” request that corresponds to the ecommerce order tracking and go to the “Payload” tab, I see “null” values where there should be items ids:


    Also, there is no sign of items variants in the payload.

@asinior the order didn’t show up in the ecommerce report. I have an abandoned cart instead:

Is there a way to resolve this without having to edit the dataLayer to make these objects as strings from the start?

Can you send me the URL of the site here or via dm? I will verify this.

Hi,
I am having the same issue with the ecommerce tag, I was wondering if you managed to resolve this?

Thanks a lot!

Hello,

My dataLayer structure was a bit specific + some values didn’t have the right format: numbers instead of strings.

Because of these 2 reasons, @asinior (thank you again :slight_smile:) redirected me to the following solution: using a custom code instead of the built-in ecommerce order tag.

I ended up using this code, it works perfectly in my case:

<script>
  (function () {

  window._paq = window._paq || [];
  var products = {{ items }}.map(function(product) {
    return {
      sku: String(product.id),
      name: product.name,
      price: product.price,
      variant: String(product.variant),
      quantity: product.quantity
    };
  });
  
  var paymentInformation = {
      orderId: String({{ transaction_id }}),
      grandTotal: {{ value }},
      subTotal: {{ value }} - {{ shipping }},
      tax: {{ tax }},
      shipping: {{ shipping }}
  };
  
  _paq.push(["ecommerceOrder", products, paymentInformation]);  

    })();
</script>

Even if you also need to go for the custom code solution, there’s a good chance you’ll need to tweak it a bit to fit your dataLayer structure.

I hope this will help.