Skip to content

Instantly share code, notes, and snippets.

@radrice
Created February 9, 2016 15:41
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save radrice/f7e9bc0f93ce8fd4912a to your computer and use it in GitHub Desktop.
Save radrice/f7e9bc0f93ce8fd4912a to your computer and use it in GitHub Desktop.
A quick setup for AngularJS + FullStory
/*
A kludgey example of how to use FullStory with AngularJS.
Just shove it into .run :-)
Do with it as you please, but use at your own risk.
This is not officially sanctioned code and intended to provide an example
of how FullStory is implemented in an Angular application.
*/
(function(){
'use strict';
angular.module('yourApp')
.run(function($rootScope, $location, Auth, userService, appAlert) {
/*
This is where I insert the FS snippet...
*/
window['_fs_debug'] = false;
window['_fs_host'] = 'fullstory.com';
window['_fs_org'] = 'yourID';
(function(m,n,e,t,l,o,g,y){
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='//'+_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){FS(l,v)};
g.identifyAccount=function(i,v){o='account';v=v||{};v.acctId=i;FS(o,v)};
g.clearUserCookie=function(d,i){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,'FS','script','user');
/*
Using a custom Auth service here via firebase.
If you have an auth service, just create an onAuth event to know when to fire FS.identify...
*/
Auth.$onAuth(function(authData) {
/*
authData is just a user object my auth service
provides on successful login e.g.:
authData = {
uid: '123xyz',
displayName: 'Lemmy Kilmister',
email: 'lemmy@motorhead.com',
lifetimeSpend: 1000000000
}
*/
if (authData) {
FS.identify(authData.uid, {
displayName: authData.userName ? authData.userName : authData.email,
email: authData.email,
// this is an example of a _real number custom variable
lifetimeSpend_real: authData.lifetimeSpend
});
} else {
/*
Just clears the cookie if an auth event occurs without authData, which in this case is a logout event
*/
FS.clearUserCookie();
}
});
})
})();
@ahmed-saleh
Copy link

thanks +1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment