Liquid, JavaScript, Themes
Hey ich würde gerne Googles Remarketing nutzen, meine erste automatisierte Kampagne läuft auch schon - aber schlecht. Und Google sagt mir, dass das Tag ecomm_prodid nicht im Feed auftaucht.
Ich will deshlab diesem Code auf der Shop Seite hinterlegen im Template (mit meinen IDs)
Wenn ich ihn einfüge, sagt mir Shopify, dass das letzte {% endif %} ein ungültiges Tag wäre.
Woran liegt das?
{% if template contains 'product' or template contains 'collection' or template contains 'index' or template contains 'search' or template contains 'cart' %}
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-PROPERTY_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-PROPERTY_ID', {'send_page_view': false, 'custom_map': {'dimension1': 'ecomm_prodid', 'dimension2': 'ecomm_pagetype', 'dimension3': 'ecomm_totalvalue'}});
gtag('config', 'AW-GOOGLE_CONVERSION_ID');
</script>
<script>
gtag('event', 'page_view', {
'ecomm_pagetype': '{% if template contains 'collection' %}category{% elsif template contains 'search' %}searchresults{% elsif template contains 'product' %}product{% elsif template contains 'cart' %}cart{% elsif template contains 'index' %}home{% endif %}',{% endif %}
{% if template contains 'product' %}
'ecomm_prodid': 'shopify_US_{{ product.id }}_{% if product.variants.first.id %}{{ product.variants.first.id }}',{% else %}{{ product.variants.id }}',{% endif %}
'ecomm_totalvalue': {{ product.price_min | money_without_currency | replace: ',', '.' }},
{% elsif template contains 'cart' %}
'ecomm_prodid': [{% for item in cart.items %}'shopify_US_{{ item.product_id }}_{{ item.variant_id }}'{% unless forloop.last %}, {% endunless %}{% endfor %}],
'ecomm_totalvalue': {{ cart.total_price | money_without_currency | replace: ',', '.' }},
{% endif %}
'non_interaction': true
});
</script>
{% endif %}
Gelöst! Zur Lösung
Erfolg.
@Weinfreak – in dem Code gibt's 4x ein öffnendes if und 5x ein schließendes endif. Darüber beschwert sich der Parser zurecht.
Ich vermute, dass das letzte {% endif %} am Ende dieses Blocks überschüssig ist:
… template contains 'index' %}home{% endif %}',{% endif %}
… oder alternativ vor
'ecomm_pagetype': …
ein {% if … %} fehlt.
LG, Mario
Erfolg.
@Weinfreak – in dem Code gibt's 4x ein öffnendes if und 5x ein schließendes endif. Darüber beschwert sich der Parser zurecht.
Ich vermute, dass das letzte {% endif %} am Ende dieses Blocks überschüssig ist:
… template contains 'index' %}home{% endif %}',{% endif %}
… oder alternativ vor
'ecomm_pagetype': …
ein {% if … %} fehlt.
LG, Mario
Danke jetzt funzt es!
@Weinfreak – nachdem ich das komplett refactort hab, werd ich die Lösung in einen Blogbeitrag gießen und hier posten, wenn ich den denn online hab 😉
Shopify unterstützt die weltweit innovativsten Marken und Unternehmer:innen. Um Unterne...
By SarahF_Shopify Mar 25, 2024Was ist ein kleines Element eines Shopify Shops mit großer Wirkung? Ein Element ganz we...
By Kai Mar 14, 2024Was genau ist POD? Von T-Shirts bis hin zu Plakaten, Kaffeetassen, Wandmatten, alles was m...
By Kai Feb 29, 2024