wendy0751 / gtm

gtm
0 stars 0 forks source link

Tracking 媽媽餵 #1

Open wendy0751 opened 7 years ago

wendy0751 commented 7 years ago

Adwords Conversion Tracking

wendy0751 commented 7 years ago

<script type="text/javascript">

if (location.pathname == '/' && location.hostname == "www.mamaway.com.tw") { var google_tag_params = { dynx_pagetype: 'home' }; }

else if (location.pathname.search("./product%20search/.") > -1 && location.hostname == "www.mamaway.com.tw") { var google_tag_params = { dynx_pagetype: 'searchresults' }; }

else if (location.pathname.search("./product%20detail/.") > -1 && location.hostname == "www.mamaway.com.tw") { var google_tag_params = { dynx_itemid: document.getElementsByClassName('number')[0].innerText.match(/[^產品編號:]+/g)[0], dynx_pagetype: 'product' }; }

else if (location.pathname == "/shopcart/" && location.hostname == "www.mamaway.com.tw") { var productList_adwords = document.getElementsByClassName('font-small gary'); var iamcontainer_adwords = [];

for (i=0;i<productList_adwords.length;i++) {
  iamcontainer_adwords.push(document.getElementsByClassName('font-small gary')[i].innerText.match(/[^產品編號:]+/g)[0])
}

var google_tag_params = {
    dynx_itemid: iamcontainer_adwords,
    dynx_pagetype: 'cart',
    dynx_totalvalue: parseInt(document.getElementById('Bill_Order_Money').innerHTML)
  };
var IAMJASON_adwords = JSON.stringify(iamcontainer_adwords);
localStorage.setItem('productList_adwords',IAMJASON_adwords);

localStorage.setItem('priceJSON',document.getElementById('Bill_Order_Money').innerHTML);

}

else if (location.pathname.search("shopcart") > -1 && location.pathname.search("order") > -1 && location.hostname == "www.mamaway.com.tw") { var google_tag_params = { dynx_itemid: JSON.parse(localStorage.getItem('productList_adwords')), dynx_pagetype: 'conversion', dynx_totalvalue: parseInt(localStorage.getItem('priceJSON')) };

localStorage.removeItem('productList_adwords')
localStorage.removeItem('priceJSON')

}

else { var google_tag_params = { dynx_pagetype: 'other' }; }

[](url) >
wendy0751 commented 7 years ago

Google Adwords Dynamic Remarketing

`<script` type="text/javascript">

if (location.pathname == '/' && location.hostname == "www.mamaway.com.tw") {
    var google_tag_params = {
        dynx_pagetype: 'home'
      };
}

else if (location.pathname.search(".*/product%20search/.*") > -1 && location.hostname == "www.mamaway.com.tw") {
    var google_tag_params = {
        dynx_pagetype: 'searchresults'
      };
}

else if (location.pathname.search(".*/product%20detail/.*") > -1 && location.hostname == "www.mamaway.com.tw") {
    var google_tag_params = {
        dynx_itemid: document.getElementsByClassName('number')[0].innerText.match(/[^產品編號:]+/g)[0],
        dynx_pagetype: 'product'
      };
}

else if (location.pathname == "/shopcart/" && location.hostname == "www.mamaway.com.tw") {
    var productList_adwords = document.getElementsByClassName('font-small gary');
    var iamcontainer_adwords = [];

    for (i=0;i<productList_adwords.length;i++) {
      iamcontainer_adwords.push(document.getElementsByClassName('font-small gary')[i].innerText.match(/[^產品編號:]+/g)[0])
    }

    var google_tag_params = {
        dynx_itemid: iamcontainer_adwords,
        dynx_pagetype: 'cart',
        dynx_totalvalue: parseInt(document.getElementById('Bill_Order_Money').innerHTML)
      };
    var IAMJASON_adwords = JSON.stringify(iamcontainer_adwords);
    localStorage.setItem('productList_adwords',IAMJASON_adwords);

    localStorage.setItem('priceJSON',document.getElementById('Bill_Order_Money').innerHTML);
}

else if (location.pathname.search("shopcart") > -1 && location.pathname.search("order") > -1 && location.hostname == "www.mamaway.com.tw") {
    var google_tag_params = {
        dynx_itemid: JSON.parse(localStorage.getItem('productList_adwords')),
        dynx_pagetype: 'conversion',
        dynx_totalvalue: parseInt(localStorage.getItem('priceJSON'))
      };

    localStorage.removeItem('productList_adwords')
    localStorage.removeItem('priceJSON')
}

else  {
    var google_tag_params = {
        dynx_pagetype: 'other'
      };
}

</script>
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 869327123;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */

</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/869327123/?value=0&guid=ON&script=0"/>

</div>
</noscript>[](url)

>