我正在尝试将UTM参数传递给内部通信,以跟踪与我们聊天的用户以及他们来自哪里。
Intercom建议捕获该信息并使用jQuery cookies插件进行设置。 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>
我做错了什么?
答案 0 :(得分:0)
您是否拥有设置后的对讲脚本?
简单地让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>