【问题标题】:Passing UTM Parameters to Intercom将 UTM 参数传递给对讲机
【发布时间】:2017-08-14 22:57:16
【问题描述】:

我正在尝试将 UTM 参数传递给 Intercom,以跟踪与我们聊天的用户以及他们来自哪里。

Intercom 建议捕获该信息并使用 jQuery cookie 插件进行设置。 Here is the documentation.

我正在使用最新版本的 Cookie,并更新了 Intercom 提供的代码。

<script type="text/javascript" src=".../js/js.cookie.js"></script>

<script type="text/javascript">
function getURLParam(name) {
  return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(window.location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null;
}

jQuery(document).ready(function($) {
  if(getURLParam('utm_source') !== null) {
    Cookies.set('utm_source', getURLParam('utm_source'), {
      expires: 365,
      path: '/',
      domain: window.location.hostname,
      secure: true
    });
  }

  if(getURLParam('utm_campaign') !== null) {
    Cookies.set('utm_campaign', getURLParam('utm_campaign'), {
      expires: 365,
      path: '/',
      domain: window.location.hostname,
      secure: true
    });
  }

  if(getURLParam('utm_medium') !== null) {
    Cookies.set('utm_medium', getURLParam('utm_medium'), {
      expires: 365,
      path: '/',
      domain: window.location.hostname,
      secure: true
    });
  }
});
</script>

我知道这可以正常工作,因为使用 Chrome 开发人员工具中的 Javascript 控制台,我可以调用

Cookies.get('utm_source')

如果 URL 包含特定的 UTM 参数,则获取实际值。

但由于某种原因,这并没有传递给对讲机,用于传递该信息的代码(位于页脚中)如下所示:

<script>
  window.intercomSettings = {
   app_id: "zto7cy6x",
   "utm_source": Cookies.get('utm_source'),
   "utm_medium": Cookies.get('utm_medium'),
   "utm_campaign": Cookies.get('utm_campaign')
  };
</script>

我做错了什么?

【问题讨论】:

    标签: jquery cookies intercom


    【解决方案1】:

    你有按照设置的对讲脚本吗? 仅仅定义 window.intercomSettings 变量是不够的。您还必须拥有将这些设置发送到对讲机的对讲机脚本。

    <script>
        window.intercomSettings = {
           app_id: "zto7cy6x",
           "utm_source": Cookies.get('utm_source'),
           "utm_medium": Cookies.get('utm_medium'),
           "utm_campaign": Cookies.get('utm_campaign')
        };
    </script>
    <script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/wprz7ktj';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()</script>
    

    【讨论】:

    • Intercom 脚本确实在 window.intercomSettings 变量之后。
    • 从你的例子中删除你的app_id 可能对你有好处:)
    • 那部分只是 OP 的复制粘贴
    猜你喜欢
    • 2021-01-02
    • 2013-03-08
    • 1970-01-01
    • 2020-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多