Skip to content

Instantly share code, notes, and snippets.

@alanmcginnis
Last active July 7, 2022 21:57
Show Gist options
  • Save alanmcginnis/7590461a16d616618fc18c7587138745 to your computer and use it in GitHub Desktop.
Save alanmcginnis/7590461a16d616618fc18c7587138745 to your computer and use it in GitHub Desktop.
This is a rough outline of how you could start/stop FullStory based on user consent.
// For example purposes only
// Set up all of your variables here
// buttons, defaults, etc.
function loadFullStory(){
// Put Your FullStory Script Here
}
// Determine if FS should start recording based on an input value from a 🍪 bar or modal, really any user input
function recordingCheck(optInVal){
// Ex. Getting a cookie value
var status = getCookie(optInVal)
if(status === "accepted"){
// Make sure FullStory is available
if(typeof FS === 'function'){
FS.restart()
}else{
// If FullStory is not available, load it. This will auto start a new session.
loadFullStory()
}
}else if(status === 'declined'){
// Shutdown FullStory only if it is running
if(typeof FS === 'function'){
FS.shutdown()
}
}else{
// Set default acceptance level of declined
setCookie('fs-consent-level', 'declined')
}
}
// Ex. functions to set cookie values and run the recording check
function declineCookies(cname) {
setCookie(cname, 'declined');
recordingCheck(cname);
}
function acceptCookies(cname) {
setCookie(cname, 'accepted');
recordingCheck(cname);
}
// Event listners for buttons
declineCookiesBtn.addEventListener("click", function () {
declineCookies(cookieName)
})
acceptCookiesBtn.addEventListener("click", function () {
acceptCookies(cookieName)
})
// Intial check
recordingCheck(cookieName);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment