Shopify:在特定页面上启动FB重定向

时间:2014-09-11 23:25:21

标签: facebook shopify

我正试图在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&amp;ev=PixelInitialized" /></noscript>


{% endif %} 

theme.liquid文件保存得很好,但代码没有显示在源代码中。

1 个答案:

答案 0 :(得分:0)

那是因为博客包含articles,而不是pages

请改为尝试:

{% 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 %}