我正试图在shopify上的博客中的特定页面上启动Facebook重定目标脚本:(/ blogs / blog / URL)
我在theme.liquid文件中使用此脚本:
{% if page.url == '/blogs/blog/URL' %}
<script>(function() {
var _fbq = window._fbq || (window._fbq = []);
if (!_fbq.loaded) {
var fbds = document.createElement('script');
fbds.async = true;
fbds.src = '//connect.facebook.net/en_US/fbds.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(fbds, s);
_fbq.loaded = true;
}
_fbq.push(['addPixelId', 'XXXXXXXXXXXXXXX']);
})();
window._fbq = window._fbq || [];
window._fbq.push(['track', 'PixelInitialized', {}]);
</script>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr? id=624847270968156&ev=PixelInitialized" /></noscript>
{% endif %}
theme.liquid文件保存得很好,但代码没有显示在源代码中。
答案 0 :(得分:0)
请改为尝试:
{% if article.url == '/blogs/blog/URL' %}
A snippet like this在这种情况下非常有用:
{% assign current_url = '' %}
{% case template %}
{% when 'page' %}
{% assign current_url = page.url %}
{% when 'blog' %}
{% assign current_url = blog.url %}
{% when 'article' %}
{% assign current_url = article.url %}
{% when 'collection' %}
{% assign current_url = collection.url %}
{% when 'product' %}
{% assign current_url = product.url %}
{% endcase %}