1
我試圖將UTM參數傳遞給對講以跟蹤與我們聊天的用戶以及他們來自哪裏。將UTM參數傳遞給對講
Intercom建議捕獲該信息並使用jQuery cookies插件進行設置。 Here is the documentation。
我正在使用最新版本的Cookies並更新了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>
我在做什麼錯?
對講機腳本的確在window.intercomSettings變量之後。 – dtalexone
可能會很好,讓你從你的例子中刪除你的'app_id' :) – chafreaky
這部分只是從OP複製粘貼 – Jack