Skip to content

Instantly share code, notes, and snippets.

@itochu0523
Last active December 6, 2016 01:07
Show Gist options
  • Save itochu0523/bca3be71403cf49e7d25c146a480d21e to your computer and use it in GitHub Desktop.
Save itochu0523/bca3be71403cf49e7d25c146a480d21e to your computer and use it in GitHub Desktop.
//TD library
!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);
// Setup parameter(1-4)
var td = new Treasure({
host: 'in.treasuredata.com',
writeKey: 'TD_API_KEY', //1,TD API KEY
database: 'TD_DB_NAME' //2,TD Database Name
});
var td_table_name = 'TD_TABLE_NAME', //3,TD Table Name
im_token = 'IM_TOKEN'; // 4,IntimateMerger parameter
var i = function (j){
var imid = j.imid,
segmentIds = j.segment_eids;
segment_eids = segmentIds.join('|');
td.set(td_table_name, {imid: imid, segment_eids: segment_eids, td_global_id: 'td_global_id'});
td.trackPageview(td_table_name);
};
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = '//sync.im-apps.net/imid/segment?token=' + im_token + '&callback=' + i;
document.body.appendChild(script);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment