Employing the tracking code in WooCommerce via GTM

Employing the tracking code in WooCommerce via GTM

 

A guide for setting up GTM for e-shops in WooCommerce.

  1. create an account at https://tagmanager.google.com/#/home
  2. add your website. Tag Manager will generate for you a code from which to take your ID. Example: GTM-XXXXXX
  3. insert your GTM ID in WooCommerce administration in plugin DuracellTomi’s Google Tag Manager for WordPress. For more information, see the article on this plugin.
  4. in the plugin settings, tick off all the options in Integration – WooCommerce


  5. in Tag Manager create a new tag for tracking clicks ”Affil Dognet – click tracking“ as custom HTML where you insert the click tracking code. Trigger is every page (All pages)
  6. in Tag Manager create a new variable (Variable). The name “ecomm_pagetype“. The variable is of Data Layer Variable type. The Data Layer Variable Name is ”ecomm_pagetype“

  7. proceed as in point 6 to create “transactionId” variables where the Data Layer Variable Name is ecommerce.purchase.actionField.id, “transactionProducts” with the variable ecommerce.purchase.products and “ecomm_totalvalue” with the variable ecomm_totalvalue
  8. create another own variable, this time of Custom Javascript type and name it ”price_netto“. Insert the code in it:
    function(){
        try{
            var value = {{ecomm_totalvalue}};
    		var netto = 0;
      
            netto = value / 1.2;
            return netto;
        }
        catch(e){
        }
    }

  9. create another own variable in GTM of Custom JavaScript type named productList and insert this code in it:
    function(){
        try{
            var list = "";
            var tp = {{transactionProducts}};
    		var x = 0;
      
            if (tp){
                for (x=0; x<tp.length; x++){
                  list += tp[x].name;
    	     list += ", ";
                }
            }
            return list;
        }
        catch(e){
        }
    }

     

  10. in Tag Manager create a new trigger named Sale Page. This trigger will be for DOM ready ”Some DOM Ready Events“ in which ecomm_pagetype is equal to the value “purchase“



     

  11. create a tag for tracking sales “Affil Dognet – sale tracking“ as custom HTML where to insert the sale tracking code. The trigger is Sale page. In enhanced settings, set up the tag so that it is run only once per page.
  12. publish all changes

If necessary, contact us, we can also set up GTM for you 😉

 

 

Click tracking code

”XXXXXXXXXXX“ needs to be substituted for your account ID, as does “YYYYYY“ for your campaign ID.

 

<script type="text/javascript" id="pap_x2s6df8d" src="https://login.dognet.sk/scripts/fj27g82d"></script>
<script type="text/javascript">
PostAffTracker.setAccountId('XXXXXXXXXXX');
try {
var CampaignID='YYYYYYYY';
PostAffTracker.track();
} catch (err) { }
</script>

 

Sale tracking code

”XXXXXXXXXXX“ needs to be substituted for your account ID, as does “YYYYYY“ for your campaign ID.

 

<script type="text/javascript" id="pap_x2s6df8d" src="https://login.dognet.sk/scripts/fj27g82d"></script>
<script type="text/javascript">
PostAffTracker.setAccountId('XXXXXXXXXXX');
var sale = PostAffTracker.createSale();
sale.setCampaignID('YYYYYYYY');
sale.setTotalCost({{price_netto}});
sale.setOrderID({{transactionId}}); 
sale.setProductID({{productList}}); 

PostAffTracker.register();
</script>
Katka Novotná
Katka Novotná

Viac ako dva roky som pracovala na pozícií e-commerce marketér a zvyšovala som obraty rôznym eshopom. Niektoré z nich sa vyšplhali až na Shop Roku (ocenenie od Heureka.sk). Mám skúsenosti s PPC Adwords aj Facebook. Analytics mi je veľmi blízky. Pre reklamnú agentúru Wiktor Leo Burnett som pomáhala s UX/UI webových projektov a aplikácií pre veľkých klientov. Vo voľnom čase tvorím webové stránky založené prevažne na WordPresse.

More articles that might interest you

Which campaigns are available in our network?