带有FB Bot的Google跟踪代码管理器中的无效HTML,CSS或JavaScript错误 [英] Invalid HTML, CSS, or JavaScript error in Google Tag Manager with FB Bot

查看:269
本文介绍了带有FB Bot的Google跟踪代码管理器中的无效HTML,CSS或JavaScript错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将以下Facebook机器人代码放入Google跟踪代码管理器中,但会收到模板中发现无效的HTML,CSS或JavaScript".错误.知道为什么吗?

I'm trying to put the following Facebook bot code into Google Tag Manager but am getting the "Invalid HTML, CSS, or JavaScript found in template." error. Any idea why?

<!-- Load Facebook SDK for JavaScript -->
<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = 'https://connect.facebook.net/en_US/sdk/xfbml.customerchat.js#xfbml=1&version=v2.12&autoLogAppEvents=1';
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

<!-- Your customer chat code -->
<div class="fb-customerchat"
  attribution="setup_tool"
  page_id="1393263590925062">
</div>

推荐答案

GTM不允许使用非标准的HTML属性.因此,HTML元素中的"attribution"和"page_id"将导致GTM抛出错误.

GTM does not allow non-standard HTML attributes. Hence "attribution" and "page_id" in the HTML element will cause GTM throw error.

您可以使用Javascript生成聊天代码.经过测试,可以正常工作.

You can use Javascript to generate the chat code. Tested and it works.

<script>
  (function() {
    var el = document.createElement('div');
    el.className = 'fb-customerchat';
    el.setAttribute('page_id', '{{Constant - Facebook Page ID}}');
    el.setAttribute('attribution', 'setup_tool');
    document.body.appendChild(el);
  })();
</script>

p/s:您可以将变量{{Constant - Facebook Page ID}}替换为页面ID.最佳做法是使用用户定义的常量变量,请在此处中阅读.

p/s: You can replace the variable {{Constant - Facebook Page ID}} with the page ID. It is best practice to use user-defined constant variables, read here.

这篇关于带有FB Bot的Google跟踪代码管理器中的无效HTML,CSS或JavaScript错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆