Skip to content

Instantly share code, notes, and snippets.

#
# Usage: ttd.py <jobid>
#
# This program send ttd_id list with segment_name to The Trade Desk
# by thier APIs.
# Query result of <jobid> requires ttd_id and segment_name.
#
#
import os
import sys
<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;
@itochu0523
itochu0523 / New-IMtag
Created May 15, 2017 10:18
To Shige-san
<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 : {clid:{{uid}}} // ← 複数ある場合はカンマ区切りでこちらに足してください(by ito)
!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);
// Configure an instance for your database
var td = new Treasure({
host: 'in.treasuredata.com',
writeKey: 'TD_API_KEY',
database: 'TD_DB_NAME'
});
var successCallback = function(global_id) {
var el = document.createElement('img');
<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データがある場合に利用
<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データがある場合に利用
//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
-- INSERT INTO id_mapping -- Presto
With ssuid_table as
(
select
session_id
,max(ssuid) as ssuid
from tmp_id_mapping
group by session_id
),
cluid_table as
-- INSERT INTO id_mapping -- Presto
With ssuid_table as
(
select
fp_id
,max(ssuid) as ssuid
from tmp_id_mapping
group by fp_id
),
cluid_table as
SELECT
ssuid,
cluid
FROM
id_mapping
WHERE
ssuid IS NOT NULL
AND cluid != '0'