Last active
May 23, 2017 11:36
-
-
Save joe-dempsey/dd8db5a655347edb83449a0080d2af47 to your computer and use it in GitHub Desktop.
Dynamic remarketing in liquid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- Google Code for Remarketing Tag --> | |
| <!-------------------------------------------------- | |
| Remarketing tags may not be associated with personally identifiable information or placed on pages related to sensitive categories. See more information and instructions on how to setup the tag on: http://google.com/ads/remarketingsetup | |
| ---------------------------------------------------> | |
| {% assign prodid = '' %} | |
| {% assign value = '' %} | |
| {% if template contains 'index' %} | |
| {% assign pagetype = 'home' %} | |
| {% elsif template contains 'search' %} | |
| {% assign pagetype = 'searchresults' %} | |
| {% elsif template contains 'collection' %} | |
| {% assign pagetype = 'category' %} | |
| {% elsif template contains 'product' %} | |
| {% capture var_id %}{% for variant in product.variants %}{{ variant.id }}{% break %}{% endfor %}{% endcapture %} | |
| {% capture prodid %}'shopify_DK_{{ product.id }}_{{ var_id }}'{% endcapture %} | |
| {% assign pagetype = 'product' %} | |
| {% assign value = product.price %} | |
| {% elsif template contains 'cart' %} | |
| {% assign pagetype = 'cart' %} | |
| {% assign value = cart.total_price %} | |
| {% assign separator = ',' %} | |
| {% capture prodid %}[{% for item in cart.items %}{% capture var_id %}{{ item.variant_id }}{% endcapture %}{% capture product_id %}{{ item.product_id }}{% endcapture %}{% if forloop.last %}{% assign separator = ']' %}{% endif %}'shopify_DK_{{product_id}}_{{var_id}}'{{separator}}{% endfor %}{% endcapture %} | |
| {% else %} | |
| {% assign pagetype = 'other' %} | |
| {% endif %} | |
| {% if value != '' %} | |
| <script type="text/javascript"> | |
| var value = {{ value | money_without_currency | remove: "." | replace: ',', '.' | round: 2 }}; | |
| var google_tag_params = { | |
| ecomm_prodid: {{prodid}}, | |
| ecomm_pagetype: '{{pagetype}}', | |
| ecomm_totalvalue: '{{cart.total_price | money_without_currency | remove: "." | replace: ',', '.' | round: 2}}' | |
| }; | |
| google_tag_params.ecomm_totalvalue = value; | |
| </script> | |
| {% else %} | |
| <script type="text/javascript"> | |
| var google_tag_params = { | |
| ecomm_prodid: '', | |
| ecomm_pagetype: '{{pagetype}}', | |
| ecomm_totalvalue: '{{cart.total_price | money_without_currency | remove: "." | replace: ',', '.' | round: 2}}' | |
| }; | |
| </script> | |
| {% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment