Skip to content

Instantly share code, notes, and snippets.

@itochu0523
Created December 5, 2018 01:32
Show Gist options
  • Save itochu0523/5582c4b2759289a46f95a7fce486df3c to your computer and use it in GitHub Desktop.
Save itochu0523/5582c4b2759289a46f95a7fce486df3c to your computer and use it in GitHub Desktop.
<script type="text/javascript">
!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=["blockEvents","unblockEvents","setSignedMode","setAnonymousMode","resetUUID","addRecord","fetchGlobalID","set","trackEvent","trackPageview","trackClicks","ready"],n=0;n<s.length;n++){var c=s[n];e[t].prototype[c]=r(c)}var o=document.createElement("script");o.type="text/javascript",o.async=!0,o.src=("https:"===document.location.protocol?"https:":"http:")+"//cdn.treasuredata.com/sdk/2.1/td.min.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(o,a)}}("Treasure",this);
var createImage = function(url) {
var img = document.createElement('img');
img.src = (('https:' == document.location.protocol) ? 'https://' : 'http://') + url;
img.width = 1;
img.height = 1;
img.style.display = 'none';
document.body.appendChild(img);
};
var sync_callback = function() {
var region = td.client.host.split('.')[0];
var account = (region === 'in' ? '':(region === 'tokyo' ? 'tokyo-':'idcf-')) + td.client.writeKey.split('/')[0];
var ttd_url = 'match.adsrvr.org/track/cmf/generic?ttd_pid=vbyog0i&ttd_tpi=1&ttd_puid='+account;
createImage(ttd_url);
};
var td = new Treasure({
host: 'in.treasuredata.com',
writeKey: 'YOUR_API_KEY',
database: 'YOUR_DB_NAME',
startInSignedMode: true
});
var td_table = 'YOUR_TABLE_NAME';
td.set('$global', 'td_global_id', 'td_global_id');
td.trackPageview(td_table, sync_callback);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment