* Custify server plugin * @link https://getanalytics.io/plugins/custify * @link https://docs.custify.com/ * @param {object} pluginConfig - Plugin settings * @param {string} pluginConfig.apiKey - custify API key * @return {AnalyticsPlugin} * @example * * custifyPlugin({ * apiKey: 'abc123'
({ apiKey })
| 14 | * }) |
| 15 | */ |
| 16 | function custifyPlugin({ apiKey }) { |
| 17 | let loaded = false; |
| 18 | return { |
| 19 | name: "custify", |
| 20 | config: { |
| 21 | apiKey, |
| 22 | }, |
| 23 | initialize: ({ config }) => { |
| 24 | makeCustifyRequest(config.apiKey, 'event', 'POST', {loaded: true}); |
| 25 | loaded = true; |
| 26 | }, |
| 27 | page: ({ payload }) => { |
| 28 | if (!loaded) return; |
| 29 | makeCustifyRequest(config.apiKey, 'event', 'POST', { |
| 30 | name: payload.properties.title, |
| 31 | user_id: payload.userId, |
| 32 | company_id: payload.companyId, |
| 33 | email: payload.email, |
| 34 | metadata: payload.properties, |
| 35 | }); |
| 36 | }, |
| 37 | track: ({ payload }) => { |
| 38 | if (!loaded) return; |
| 39 | makeCustifyRequest(config.apiKey, 'event', 'POST', { |
| 40 | name: payload.event, |
| 41 | user_id: payload.userId, |
| 42 | company_id: payload.companyId, |
| 43 | email: payload.email, |
| 44 | metadata: payload.properties, |
| 45 | }); |
| 46 | }, |
| 47 | identify: ({ payload }) => { |
| 48 | if (!loaded) return; |
| 49 | const { userId, traits } = payload; |
| 50 | makeCustifyRequest(config.apiKey, 'identify', 'POST', { |
| 51 | user_id: userId, |
| 52 | company_id: traits.companyId, |
| 53 | email: traits.email, |
| 54 | }); |
| 55 | }, |
| 56 | loaded: () => loaded, |
| 57 | }; |
| 58 | } |
| 59 | |
| 60 | function makeCustifyRequest(apiKey, endpoint, method, data) { |
| 61 | const custifyUrl = 'https://api.custify.com' |
nothing calls this directly
no test coverage detected