Last active
February 23, 2018 21:59
-
-
Save typeoneerror/aade98351af28b544ee167fa4b59c166 to your computer and use it in GitHub Desktop.
drip-es6.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
/** | |
* { | |
* success: true, | |
* visitor_uuid: "f627ee608adb01315d1022000ab2058a", | |
* anonymous: false, | |
* email: "[email protected]", | |
* custom_fields: { "name": "John" }, | |
* tags: ["Customer"], | |
* lead_score: 35 | |
* } | |
*/ | |
const DRIP_ACTIVE = true; | |
export type DripParams = { | |
[string]: mixed | |
} | |
export type DripPayload = { | |
success: boolean, | |
visitor_uuid: string, | |
anonymous: boolean, | |
email: string, | |
custom_fields: { [string]: mixed }, | |
tags: Array<string>, | |
lead_score: number | |
} | |
function dripDebug(method, ...params) { | |
console.debug(`[DRIP: ${method}]`, params); | |
} | |
export function identify(params: DripParams = {}) { | |
return new Promise(function (resolve, reject) { | |
if (!DRIP_ACTIVE) { | |
dripDebug('identify', params); | |
return resolve(); | |
} | |
window._dcq.push(['identify', { | |
...params, | |
success: function (response) { | |
resolve(response); | |
}, | |
failure: function (response) { | |
reject(response); | |
} | |
}]); | |
}); | |
} | |
export function track(event: string, params: DripParams = {}) { | |
return new Promise(function (resolve, reject) { | |
if (!DRIP_ACTIVE) { | |
dripDebug('track', event, params); | |
return resolve(); | |
} | |
window._dcq.push(['track', event, { | |
...params, | |
success: function (response) { | |
resolve(response); | |
}, | |
failure: function (response) { | |
reject(response); | |
} | |
}]); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use like: