Last active
August 11, 2018 23:23
-
-
Save jefffis/cf7d90cf6ff44a5ddf961f51d45a1ac8 to your computer and use it in GitHub Desktop.
FullStory GTM Injection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dv_fullstory(segmentName) { | |
window['_fs_debug'] = false; | |
window['_fs_host'] = 'www.fullstory.com'; | |
window['_fs_org'] = '1ZRXF'; | |
window['_fs_namespace'] = 'FS'; | |
(function(m,n,e,t,l,o,g,y){ | |
if (e in m && m.console && m.console.log) { m.console.log('FullStory namespace conflict. Please set window["_fs_namespace"].'); return;} | |
g=m[e]=function(a,b){g.q?g.q.push([a,b]):g._api(a,b);};g.q=[]; | |
o=n.createElement(t);o.async=1;o.src='https://'+_fs_host+'/s/fs.js'; | |
y=n.getElementsByTagName(t)[0];y.parentNode.insertBefore(o,y); | |
g.identify=function(i,v){g(l,{uid:i});if(v)g(l,v)};g.setUserVars=function(v){g(l,v)}; | |
g.identifyAccount=function(i,v){o='account';v=v||{};v.acctId=i;g(o,v)}; | |
g.clearUserCookie=function(c,d,i){if(!c || document.cookie.match('fs_uid=[`;`]*`[`;`]*`[`;`]*`')){ | |
d=n.domain;while(1){n.cookie='fs_uid=;domain='+d+ | |
';path=/;expires='+new Date(0);i=d.indexOf('.');if(i<0)break;d=d.slice(i+1)}}}; | |
})(window,document,window['_fs_namespace'],'script','user'); | |
var ls = window.localStorage ? true : false, | |
isLsSet = (ls && window.localStorage.getItem('segment')) ? true : false, | |
hash = { | |
visitorId_str: '{{dvVisitorId}}', | |
userId_str: '{{dvUserId}}', | |
segment_str: isLsSet ? window.localStorage.getItem('segment') : segmentName | |
}; | |
// test & set localStorage | |
if(ls) { | |
window.localStorage.setItem('fullStorySegment', hash.segment_str); | |
} | |
FS.identify('{{dvVisitorId}}', hash); | |
} | |
// if first time user | |
if('{{dvFirstTimeUser}}' == '1') { | |
if('{{dvPageType}}' === 'search') { | |
dv_fullstory('firstTimeGuestSearch'); | |
}else if('{{dvPageType}}' === 'profile' && window.location.pathname !== '/account/profile'){ | |
dv_fullstory('firstTimeGuestProfile'); | |
} | |
} | |
// if applying as a host | |
if('{{dvPageType}}' === 'become-a-sitter') { | |
dv_fullstory('applyToBeAHost'); | |
} | |
// if a host, on profile view | |
if('{{dvPageType}}' === 'profile' && window.location.pathname === '/account/profile') { | |
dv_fullstory('existingHost'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment