ovipreneur

Remarketing Tag-Richard Clarson

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