Creating a global analytics javascript variable and using those values in Google Analytics / Remarketing -


So what I'm trying to do here. I am working on an ecommerce system, which has many analytics companies. I want to create a javascript variable that they can all use.

Example of checkout page:

  & lt; script type = "text / javascript" & gt; (Function (_analytics) {_analytics.page_type = '$ page_type'; _analytics.cart = null; _analytics.order = null; _analytics.product = null; if ($ page_type == 'order_confirmation') {_analytics.order.products = []; _analytics.order.total = '$ order_total'; foreach ($ purchased_product) {_analytics.order.products.push ({'sku': $ sku, 'price': $ value, 'quantity': $ quantity} );}}} (_ Analytics = window._analytics || {})); & Lt; / Script & gt;   

This is the first tag on my page. After this tag, I include Google Analytics, Google Remarketing, and other analytics scripts. In those scripts I will loop through javascript variables which have already been created to track the purchase.

Remarketing tag that comes after the first tag:

  & lt; script type = "text / javascript" & gt; Var google_tag_params = {ecomm_prodid: '', ecomm_pagetype: _analytics.page_type, ecomm_totalvalue = _analytics.order.total; }; / * & Lt ;! [CDATA [* / var google_conversion_id = XXXXXX; var google_custom_params = window.google_tag_params; Var google_remarketing_only = true; / *]] & Gt; * / & lt; / Script & gt;   

Has any loss or damage, which should be known while trying to apply it in such a way? Google Tag Assistant complains that the Google Remarketing page type variable is set incorrectly, but if I get console.log (google_tag_params.ecomm_pagetype) the correct value.

Just someone has such a problem / question, I understand it. I was using a "Dummy" remarketing ID to test (0000). Obviously, comment tags did not like this value Once I changed it into the actual remarketing ID, it worked fine.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -