Leverage Enhanced Ecommerce Data Layer for Marketing Pixels

Comments:14

  1. Hi Ana! Thanks a lot for this great article, I have been looking for those JS utilities lately and again found the answer at your blog;) Regarding the external pixels are now covered, but how about enhancing the eCommerce data layer to send extra parameters to GA (for dynamic remarketing) ? Is it always a modification of the code needed (so it populates as well: (for retail (for instance)) ecomm_prodid, ecomm_pagetype, ecomm_totalvalue to data layer directly? Or you could think of a JS that would convert the enhanced ecommerce data from the standard implementation into the format that would match custom dimensions in GA. Just like Patrick Strickler did for Client, Session, Hit IDs in one of his articles. Please check the article attached. Not sure if this a good idea, just struggling with it this days…

    1. Hey Anton, thanks for the comment! For dynamic remarketing you can use the data layer values that are already there: ‘id’ and ‘revenue’ for ‘ecomm_prodid’ and ‘ecomm_totalvalue’. You’d extract those values into GTM with custom JS variables and/or DL variables and attach them to your dynamic remarketing tag. Page type isn’t part of the default EE data layer, though, so you’d need to push that in separately, like this:

      window.dataLayer = window.dataLayer || [];
      dataLayer.push({
        'event' : 'pageview',
        'pageType' : 'checkout'
      });
      

      If you wanted you could bundle in ‘pageType’ as part of your EE data layer push, but I usually see it pushed separately.
      I’m not totally sure what you mean by ‘JS that would convert the enhanced ecommerce data from the standard implementation into the format that would match custom dimensions in GA’, can you please clarify what you’re looking for?

  2. Hi Ana, great great tips… I tried use your subset product var but it doesn´t works. Then i try modify the SKU script to create a subset products but it doesn´t works too. Do you know why this script it doesn´t works based in your scripts??
    function(){
    var prods = {{DL – Ecommerce}}.purchase.products;
    var name = [];
    var price = [];
    var quantity = [];
    var i;
    if (!prods) { return; }
    for (i = 0; i < prods.length; i++) {
    if (prods[i].id) { name.push(prods[i].id),price.push(prods[i].id),quantity.push(prods[i].id); }
    }
    return prods.join('|');
    }

    1. Hey Lolo, can you please double-check that you’re using the Enhanced Ecommerce (not Standard Ecommerce) data layer on your site? If the data layer doesn’t exactly match the Enhanced Ecommerce syntax, the rest of the scripts won’t work either. But if it does match, there shouldn’t be any issue.

      To trouble-shoot, I suggest turning on GTM preview mode, making a test transaction, and checking what value gets passed into your {{DL – Ecommerce}} value. You can also type the word ‘dataLayer’ into your dev tools console to see the entire ecommerce data layer.

      1. hi!! i set the EEC in GA and i´m using GTM4WP, in a woocommerce site. I can´t see values in the DL Var into data layer. I don´t know if the script is correct (i don´t know a lot about programming). In other cases using your original scripts (array sku) i get the values into RT report of GA. With other scripts of this post, i get values into GTM preview mode, (with [ ]) but not in RT report of GA

      2. I don’t really know anything about how GTM4WP creates a data layer. However, since the Array of SKUs script works, it implies they’re using the Enhanced Ecommerce data layer, so it seems like everything else should work as well. The Array of SKUs script creates an array, while some of the other scripts create strings and numbers, so maybe your report requires an array (I don’t know what the RT report is).

        Your script above seems like you’re trying to populate several different arrays at the same time, but you’re sending the same value (prods[i].id) into each one of them and then not returning any of those arrays anyway. What is the final output you’re looking for?

  3. RT means Real Time Report in Google Analytics, sorry 🙂
    My last intent:
    JS-Productos Ecommerce:
    function(){
    var prods = {{DL – Ecommerce}}.purchase.products;
    var name = [];
    var price = [];
    var quantity = [];
    var i;
    if (!prods) { return; }
    for (i = 0; i < prods.length; i++) {
    if (prods[i].id) { name.push(prods[i].name);price.push(prods[i].price);quantity.push(prods[i].quantity); }
    }
    return prods.join('|');
    }

    I get this value into this JS var:
    '[object Object]'
    Maybe the script is not writed correctly?
    Thanks a lot for your support. Is great!!

    1. Hey, I’m not totally sure what you want the output to look like, but this doesn’t look correct to me.
      Your script looks like it does this:
      1) sets the var ‘prods’ as the products object.
      2) defines 3 new variables: name, price, and quantity.
      3) pushes all the product names into the name variable, the prices into the price variable, and the quantities into the quantity variable
      4) returns the prods var, which is still the same object you started with.

      If you’re trying to return multiple variables, I suggest checking the ‘subset of product attributes’ script. But it really depends on what you’re looking to get at the end.

      1. Thanks for your comments. The topic is with your subset script i collect the next values:
        [
        {name: ‘Camiseta cascuda’, quantity: 1, price: 52},
        {name: ‘Hoodie con bolsillo canguro’, quantity: 1, price: 75}
        ]
        but in Google Analytics with this label tag event:
        “Compra Finalizada: Total: {{JS – Total Price}} € | Subset Atributos: {{JS-Subset Atributos}}”
        i get this in Google Analytics Real Time Report:
        “Compra Finalizada: Total: 128 € | Subset Atributos: {{[object Object], [object Object]}}
        For this reason i tried by other of your scripts 🙁

      2. OK, I finally understand what you’re trying to do :p
        The output of the subset of product attributes script is a JSON object, which can’t be displayed in Google Analytics event fields. These scripts were designed for marketing pixels, not for GA.
        If you want to pass values into GA, you need to make sure those values are strings, not objects. The easiest way is probably to just make a new custom JS variable like this:

        function(){
         return JSON.stringify({{JS – Product Attributes}});
        }

        That will return your product attributes object as a string, so you can then add this new variable into your event tag.

  4. Hi, GREAT SUPPORT!! Now i understand. Then, you means that to collect in GA the data i want in a subset, i have to create a CJS var, and paste the next inside:
    function(){
    return JSON.stringify({{JS – Product Attributes}});
    }
    isn´t it?
    The next question is if you have any course than show how work with GMT-EEC-Ads Pixels (Facebook&Google Ads). I´m very interested in your way of teach. This post help me a lot!! And your support much more!! 🙂

    1. How can i delete the next simbols in Attributtes names e.g “categoria”-“producto”- “precio” – “cantidad”:
      ” , { , and [
      and how can i separate products with “|” symbol in the collected string with your function:
      Subset Atributos: [{“categoria”:”Sweaters”,”producto”:”Hoodie con bolsillo canguro”,”precio”:75,”cantidad”:1,”talla”:”xl”},{“categoria”:”Cap”,”producto”:”Gorra de pana orgánica y PIÑATEX”,”precio”:53,”cantidad”:1}]

      to get something like this:

      Subset Atributos: [categoria:”Sweaters”, producto:”Hoodie con bolsillo canguro”, precio:75, cantidad:1, talla:”xl” | categoria:”Cap”, producto:”Gorra de pana orgánica y PIÑATEX”, precio:53, cantidad:1]

      1. I think the replace method probably does what you want. For example, this would remove all the quotation marks:

        function(){
         return JSON.stringify({{JS – Product Attributes}}).replace(/"/g,"");
        }

        This is just a JavaScript question, so you can check out some JS tutorials online and then change your output exactly the way you want.

Leave a Reply

Your email address will not be published.