ovipreneur

Google Ads Remarketing Tag-Theme

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