-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d18a7f0
commit 29bd7fb
Showing
3 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import logger from "../../utils/logUtil"; | ||
class CustomerIO { | ||
constructor(config) { | ||
this.siteID = config.siteID; | ||
this.apiKey = config.apiKey; | ||
|
||
this.name = "CUSTOMERIO"; | ||
} | ||
|
||
init() { | ||
logger.debug("===in init Customer IO init==="); | ||
window._cio = window._cio || []; | ||
let siteID = this.siteID; | ||
(function() { | ||
var a,b,c;a=function(f){return function(){window._cio.push([f]. | ||
concat(Array.prototype.slice.call(arguments,0)))}};b=["load","identify", | ||
"sidentify","track","page"];for(c=0;c<b.length;c++){window._cio[b[c]]=a(b[c])}; | ||
var t = document.createElement('script'), | ||
s = document.getElementsByTagName('script')[0]; | ||
t.async = true; | ||
t.id = 'cio-tracker'; | ||
t.setAttribute('data-site-id', siteID); | ||
t.src = 'https://assets.customer.io/assets/track.js'; | ||
s.parentNode.insertBefore(t, s); | ||
})(); | ||
} | ||
|
||
identify(rudderElement) { | ||
logger.debug("in Customer IO identify"); | ||
let userId = rudderElement.message.userId ? rudderElement.message.userId : rudderElement.message.anonymousId; | ||
let traits = rudderElement.message.context.traits ? rudderElement.message.context.traits : {}; | ||
if(!traits.created_at){ | ||
traits.created_at = (new Date()).getTime(); | ||
} | ||
traits.id = userId; | ||
window._cio.identify(traits); | ||
} | ||
|
||
track(rudderElement) { | ||
logger.debug("in Customer IO track"); | ||
|
||
let eventName = rudderElement.message.event; | ||
let properties = rudderElement.message.properties; | ||
window._cio.track(eventName, properties); | ||
|
||
} | ||
|
||
page(rudderElement) { | ||
logger.debug("in Customer IO page"); | ||
|
||
var name = rudderElement.message.name || rudderElement.message.properties.url; | ||
window._cio.page(name, rudderElement.message.properties); | ||
|
||
} | ||
|
||
isLoaded() { | ||
return !!(window._cio && window._cio.push !== Array.prototype.push); | ||
} | ||
} | ||
|
||
export { CustomerIO }; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { CustomerIO } from "./browser"; | ||
|
||
export default CustomerIO; |
This file contains 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