Skip to content

Instantly share code, notes, and snippets.

@dustinlarimer
Last active August 29, 2015 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dustinlarimer/19fedf00c44d120ef8b4 to your computer and use it in GitHub Desktop.
Save dustinlarimer/19fedf00c44d120ef8b4 to your computer and use it in GitHub Desktop.
Refactored the keen-js async paste-in script, to make the namespace and version number more accessible :)
!function(i,o){i("Keen","/3.1.0/keen.min.js",o)}(function(a,b,c){var d,e,f;c["_"+a]={},c[a]=function(b){c["_"+a].clients=c["_"+a].clients||{},c["_"+a].clients[b.projectId]=this,this._config=b},c[a].ready=function(b){c["_"+a].ready=c["_"+a].ready||[],c["_"+a].ready.push(b)},d=["addEvent","setGlobalProperties","trackExternalLink","on"];for(var g=0;g<d.length;g++){var h=d[g],i=function(a){return function(){return this["_"+a]=this["_"+a]||[],this["_"+a].push(arguments),this}};c[a].prototype[h]=i(h)}e=document.createElement("script"),e.async=!0,e.src=b,f=document.getElementsByTagName("script")[0],f.parentNode.insertBefore(e,f)},this);
(function(i,o){i("Keen","/3.1.0/keen.min.js",o);}(function(t,h,x){
// t = context
// h = file
// x = context
// console.log(t,h,x===window);
var methods, script, tag;
// _Keen cache
x['_'+t] = {};
// Keen stub
x[t] = function(e) {
x['_'+t].clients = x['_'+t].clients || {};
x['_'+t].clients[e.projectId] = this;
this._config = e;
};
// Keen.ready(function(){});
x[t].ready = function(fn){
x['_'+t].ready = x['_'+t].ready || [];
x['_'+t].ready.push(fn);
};
methods = ['addEvent', 'setGlobalProperties', 'trackExternalLink', 'on'];
for (var i = 0; i < methods.length; i++){
var method = methods[i];
var action = function(method){
return function() {
this['_'+method] = this['_'+method] || [];
this['_'+method].push(arguments);
return this;
};
};
x[t].prototype[method] = action(method);
}
script = document.createElement("script");
//script.type = "text/javascript";
script.async = !0;
script.src = h;
tag = document.getElementsByTagName("script")[0];
tag.parentNode.insertBefore(script,tag);
}, this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment