Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign up| // Olark | |
| // ----- | |
| // Last updated: October 11th, 2012 | |
| // [Documentation](http://www.olark.com/documentation). | |
| analytics.addProvider('Olark', { | |
| settings : { | |
| siteId : null, | |
| track : false | |
| }, | |
| // Changes to the Olark snippet: | |
| // | |
| // * Removed `CDATA` tags. | |
| // * Add `siteId` from stored `settings`. | |
| // * Added `window.` before `olark.identify`. | |
| initialize : function (settings) { | |
| settings = analytics.utils.resolveSettings(settings, 'siteId'); | |
| analytics.utils.extend(this.settings, settings); | |
| window.olark||(function(c){var f=window,d=document,l=f.location.protocol=="https:"?"https:":"http:",z=c.name,r="load";var nt=function(){f[z]=function(){(a.s=a.s||[]).push(arguments)};var a=f[z]._={},q=c.methods.length;while(q--){(function(n){f[z][n]=function(){f[z]("call",n,arguments)}})(c.methods[q])}a.l=c.loader;a.i=nt;a.p={0:+new Date};a.P=function(u){a.p[u]=new Date-a.p[0]};function s(){a.P(r);f[z](r)}f.addEventListener?f.addEventListener(r,s,false):f.attachEvent("on"+r,s);var ld=function(){function p(hd){hd="head";return["<",hd,"></",hd,"><",i,' onl' + 'oad="var d=',g,";d.getElementsByTagName('head')[0].",j,"(d.",h,"('script')).",k,"='",l,"//",a.l,"'",'"',"></",i,">"].join("")}var i="body",m=d[i];if(!m){return setTimeout(ld,100)}a.P(1);var j="appendChild",h="createElement",k="src",n=d[h]("div"),v=n[j](d[h](z)),b=d[h]("iframe"),g="document",e="domain",o;n.style.display="none";m.insertBefore(n,m.firstChild).id=z;b.frameBorder="0";b.id=z+"-loader";if(/MSIE[ ]+6/.test(navigator.userAgent)){b.src="javascript:false"}b.allowTransparency="true";v[j](b);try{b.contentWindow[g].open()}catch(w){c[e]=d[e];o="javascript:var d="+g+".open();d.domain='"+d.domain+"';";b[k]=o+"void(0);"}try{var t=b.contentWindow[g];t.write(p());t.close()}catch(x){b[k]=o+'d.write("'+p().replace(/"/g,String.fromCharCode(92)+'"')+'");d.close();'}a.P(2)};ld()};nt()})({loader: "static.olark.com/jsclient/loader0.js",name:"olark",methods:["configure","extend","declare","identify"]}); | |
| window.olark.identify(this.settings.siteId); | |
| }, | |
| identify : function (userId, traits) { | |
| // Choose the best name for the user that we can get. | |
| var name = userId; | |
| if (traits && traits.email) name = traits.email; | |
| if (traits && traits.name) name = traits.name; | |
| // If we ended up with no name after all that, get out of there. | |
| if (!name) return; | |
| window.olark('api.chat.updateVisitorNickname', { | |
| snippet : name | |
| }); | |
| }, | |
| track : function (event, properties) { | |
| // Check the `track` setting to know whether log events or not. | |
| if (!this.settings.track) return; | |
| window.olark('api.chat.sendNotificationToOperator', { | |
| body : 'Visitor triggered "'+event+'".' | |
| }); | |
| } | |
| }); | |