JavaScript编译器错误-Facebook Pixel GTM

时间:2018-10-17 15:57:25

标签: google-tag-manager facebook-pixel

在这里感谢帮助。我删除了该帖子的fb ID,但该帖子位于GTM中。

从GTM获取此错误:第13行的错误,字符5:解析错误。 '}'预期

<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'blocked-out-my-id', { 
  em: '{{_email_}}', 
  // Data will be hashed automatically via a dedicated function in FB pixel
    ph: '{{_phone_number_}}',
    fn: '{{_FirstName_}}'
    ln: '{{_LastName_}}'
    ct: '{{_city_}}'
    st: '{{_state_}}'
    zp: '{{_zip_code_}}'
    country: '{{_country_}}'
    ge: '{{_gender_}}'
    db: '{{_dob_}}'
});
fbq('track', 'PageView');
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=blocked-out-my-id&ev=PageView&noscript=1"
/></noscript>
<!-- DO NOT MODIFY -->
<!-- End Facebook Pixel Code -->

2 个答案:

答案 0 :(得分:0)

对象中需要逗号。具体来说:

fbq('init', 'blocked-out-my-id', { 
  em: '{{_email_}}', 
  // Data will be hashed automatically via a dedicated function in FB pixel
    ph: '{{_phone_number_}}',
    fn: '{{_FirstName_}}',
    ln: '{{_LastName_}}',
    ct: '{{_city_}}',
    st: '{{_state_}}',
    zp: '{{_zip_code_}}',
    country: '{{_country_}}',
    ge: '{{_gender_}}',
    db: '{{_dob_}}'
});

答案 1 :(得分:0)

使用fbq函数,您正在将对象用作函数参数。该对象包含键值对,例如ph:'{{ email }}。每个键值对的末尾都必须有一个“,”,最后一个除外,例如:

<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'blocked-out-my-id', { 
  em: '{{_email_}}', 
  // Data will be hashed automatically via a dedicated function in FB pixel
    ph: '{{_phone_number_}}',
    fn: '{{_FirstName_}}',
    ln: '{{_LastName_}}',
    ct: '{{_city_}}',
    st: '{{_state_}}',
    zp: '{{_zip_code_}}',
    country: '{{_country_}}',
    ge: '{{_gender_}}',
    db: '{{_dob_}}'
});
fbq('track', 'PageView');
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=blocked-out-my-id&ev=PageView&noscript=1"
/></noscript>
<!-- DO NOT MODIFY -->
<!-- End Facebook Pixel Code -->

此外,我不确定100%是否需要在GTM变量之前使用',大多数变量可能已经包含字符串值。