Advertisement
ovipreneur

Dynamic remarketing tag(Theme)-print by sparker

Dec 14th, 2021
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {% comment %}
  2. Google Ads Dynamic Remarketing Script by ovi
  3. {% endcomment %}
  4.  
  5. {% comment %}Set to false if GTAG is already loaded on the page. Leave to true if unsure.{%endcomment%}
  6. {% assign load_gtag = true %}
  7.  
  8. {% comment %} Enter your google conversion id below {% endcomment %}
  9. {% assign google_conversion_id = "10815076931" %}
  10.  
  11. {% assign shopify_store_country  = 'AU' %}
  12.  
  13. {%if load_gtag %}
  14. <!-- Global site tag (gtag.js) -->
  15. <script async src="https://www.googletagmanager.com/gtag/js?id=AW-{{ google_conversion_id }}"></script>
  16. {% endif %}
  17. <script>
  18.   window.dataLayer = window.dataLayer || [];
  19.   function gtag(){dataLayer.push(arguments);}
  20.   gtag('js', new Date());
  21.   gtag('config', 'AW-{{ google_conversion_id }}');
  22. </script>
  23.  
  24. {% assign google_event = false %}
  25. {% assign google_items = false %}
  26. {% assign google_value = false %}
  27. {% if template contains 'cart' %}
  28.     {% assign google_event = 'add_to_cart' %}
  29.     {% capture google_items %}{% for item in cart.items %}{'id':'shopify_{{ shopify_store_country  }}_{{ item.product.id }}_{{ item.variant.id }}','google_business_vertical': 'retail'}{% unless forloop.last %}, {% endunless %}{% endfor %}{% endcapture %}
  30.     {% assign google_value = cart.total_price %}
  31. {% elsif template contains 'collection' %}
  32.     {% assign google_event = 'view_item_list' %}
  33.     {% capture google_items %}{% for item in collection.products limit:5 %}{'id':'shopify_{{ shopify_store_country  }}_{{ item.id }}_{{ item.variants.first.id }}','google_business_vertical': 'retail'}{% unless forloop.last %}, {% endunless %}{% endfor %}{% endcapture %}
  34. {% elsif template contains 'product' %}
  35.     {% assign google_event = 'view_item' %}
  36.     {% capture google_items %}{'id':'shopify_{{ shopify_store_country  }}_{{ product.id }}_{{ product.selected_or_first_available_variant.id }}','google_business_vertical': 'retail'}{% endcapture %}
  37.     {% assign google_value = product.selected_or_first_available_variant.price %}
  38. {% elsif template contains 'search' %}
  39.     {% assign google_event = 'view_search_results' %}
  40.     {% capture google_items %}{% for item in search.results limit:5 %}{'id':'shopify_{{ shopify_store_country  }}_{{ item.id }}_{{ item.variants.first.id }}','google_business_vertical': 'retail'}{% unless forloop.last %}, {% endunless %}{% endfor %}{% endcapture %}
  41. {% endif %}
  42.  
  43. {% if google_event %}
  44. <script>
  45.     gtag('event', '{{ google_event }}', {
  46.       'send_to': 'AW-{{ google_conversion_id }}',
  47.       {% if google_value %}'value': '{{ google_value | divided_by: 100.0 }}',{% endif %}
  48.       'items': [{{ google_items }}]
  49.     });
  50. </script>
  51. {% endif %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement