MCPcopy Create free account
hub / github.com/DavidWells/analytics / customerIOServer

Function customerIOServer

packages/analytics-plugin-customerio/src/node.js:23–58  ·  view source on GitHub ↗

* Customer.io analytics server side integration. Uses https://github.com/customerio/customerio-node * @link https://getanalytics.io/plugins/customerio/ * @link https://customer.io/docs/api/ * @param {object} pluginConfig - Plugin settings * @param {string} pluginConfig.siteId - Customer.io site

(pluginConfig = {})

Source from the content-addressed store, hash-verified

21 * })
22 */
23function customerIOServer(pluginConfig = {}) {
24 // Allow for userland overides of base methods
25 if (!pluginConfig.siteId) {
26 throw new Error('customer.io siteId missing')
27 }
28 if (!pluginConfig.apiKey) {
29 throw new Error('customer.io apiKey missing')
30 }
31 const client = new CustomerIO(pluginConfig.siteId, pluginConfig.apiKey)
32 return {
33 name: 'customerio',
34 config: pluginConfig,
35 // page view
36 page: ({ payload }) => {
37 const { userId, properties } = payload
38 if (!userId) return false
39
40 client.trackPageView(userId, properties.url)
41 },
42 // track event
43 track: ({ payload }) => {
44 const { userId, event, properties } = payload
45 if (!userId) return false
46
47 client.track(userId, {
48 name: event,
49 data: properties
50 })
51 },
52 // identify user
53 identify: ({ payload }) => {
54 const { userId, traits } = payload
55 client.identify(userId, traits)
56 }
57 }
58}
59
60export default customerIOServer

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected