Skip to content

Instantly share code, notes, and snippets.

@itochu0523
Created December 6, 2016 02:25
Show Gist options
  • Save itochu0523/70de7d1d9cbc0ac56a6c50a8f06fe7c2 to your computer and use it in GitHub Desktop.
Save itochu0523/70de7d1d9cbc0ac56a6c50a8f06fe7c2 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
var _tdOptions = {
initParams : {
host: 'in.treasuredata.com',
writeKey: 'YOUR_WRITE_KEY',
database: 'DATABASE_NAME'
},
table : 'TABLE_NAME',
imToken : 'YOUR_IM_API_TOKEN',
// customParam : {type:"customedata"} //customeデータがある場合に利用
// overwriteParam : {td_title : "dummy"}, //基本項目を上書きしたい場合に利用
// trackClicks : true //defaultはfalse
// trackCrossDomain : true //defaultはfalse
// successCallback : function() {...} //データ送信正常終了時のCallbackを利用したい場合
// errorCallback : function() {...} //データ送信正常終了時のCallbackを利用したい場合
};
!function(t,e){if(void 0===e[t]){e[t]=function(){e[t].clients.push(this),this._init=[Array.prototype.slice.call(arguments)]},e[t].clients=[];for(var r=function(t){return function(){return this["_"+t]=this["_"+t]||[],this["_"+t].push(Array.prototype.slice.call(arguments)),this}},s=["addRecord","set","trackEvent","trackPageview","trackClicks","ready"],a=0;a<s.length;a++){var c=s[a];e[t].prototype[c]=r(c)}var n=document.createElement("script");n.type="text/javascript",n.async=!0,n.src=("https:"===document.location.protocol?"https:":"http:")+"//cdn.treasuredata.com/sdk/1.7.1/td.min.js";var i=document.getElementsByTagName("script")[0];i.parentNode.insertBefore(n,i)}}("Treasure",this);
!function(a,b,c,d,e){var f=function(){};f.prototype.init=function(c){this.customParam=c.customParam||{},this.overwriteParam=c.overwriteParam||{},this.success=c.successCallback||void 0,this.fail=c.errorCallback||void 0,this.table=c.table,this.trackClicks=c.trackClicks||!1,this.trackCrossDomain=c.trackCrossDomain||!1,this.imSyncUrl=c.imSyncUrl||"//sync.im-apps.net/imid/segment?token=",this.imToken=c.imToken,this.id="tdi"+Math.random().toString(36).substring(7);var e=new b[a](c.initParams);return this.trackClicks&&e.trackClicks(),this.trackCrossDomain&&e.set("$global","td_global_id","td_global_id"),e.set(this.table,this.customParam),this.td=e,b[d].cb[this.id]=this,this},f.prototype.boot=function(){this.createScript(this.buildImSyncUrl())},f.prototype.createScript=function(a){var b=c.createElement("script");b.type="text/javascript",b.async=!0,b.src=a;var d=c.getElementsByTagName("script")[0];d.parentNode.insertBefore(b,d)},f.prototype.buildImSyncUrl=function(){return this.imSyncUrl+this.imToken+"&callback="+encodeURIComponent(d+".cb."+this.id+".imCallback")},f.prototype.imCallback=function(a){a.imid&&this.td.set(this.table,{im_id:a.imid}),a.segment_eids&&this.td.set(this.table,{segment_eids:a.segment_eids.join("|")}),this.td.trackEvent(this.table,this.overwriteParam,this.success,this.fail)},f.prototype.trackEvent=function(a,b,c){var d=this;return function(a,b,c){if("object"==typeof a)for(var e in a)a.hasOwnProperty(e)&&(d.overwriteParam[e]=a[e]);d.td.trackEvent(d.table,d.overwriteParam,b,c)}},b[d]={cb:{}};var g=(new f).init(e);b[d].trackEvent=g.trackEvent(),g.boot()}("Treasure",window,document,"TDIM",_tdOptions);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment