From 393d346b6aa53d37284e5edaeb5ae8110d05c36f Mon Sep 17 00:00:00 2001 From: Ahmed Onawale Date: Fri, 30 Aug 2024 14:27:57 +0100 Subject: [PATCH] temporarily including compiled lib files --- ...analytics-plugin-churn-zero.browser.cjs.js | 93 +++++++++++++++ .../analytics-plugin-churn-zero.browser.es.js | 91 ++++++++++++++ .../lib/analytics-plugin-churn-zero.cjs.js | 112 ++++++++++++++++++ .../lib/analytics-plugin-churn-zero.es.js | 106 +++++++++++++++++ 4 files changed, 402 insertions(+) create mode 100644 packages/analytics-plugin-churn-zero/lib/analytics-plugin-churn-zero.browser.cjs.js create mode 100644 packages/analytics-plugin-churn-zero/lib/analytics-plugin-churn-zero.browser.es.js create mode 100644 packages/analytics-plugin-churn-zero/lib/analytics-plugin-churn-zero.cjs.js create mode 100644 packages/analytics-plugin-churn-zero/lib/analytics-plugin-churn-zero.es.js diff --git a/packages/analytics-plugin-churn-zero/lib/analytics-plugin-churn-zero.browser.cjs.js b/packages/analytics-plugin-churn-zero/lib/analytics-plugin-churn-zero.browser.cjs.js new file mode 100644 index 00000000..bef29f6e --- /dev/null +++ b/packages/analytics-plugin-churn-zero/lib/analytics-plugin-churn-zero.browser.cjs.js @@ -0,0 +1,93 @@ +'use strict'; + +require('unfetch'); + +/* global ChurnZero */ + +/** + * ChurnZero plugin + * @link https://getanalytics.io/plugins/churn-zero + * @link https://support.churnzero.com/hc/en-us/articles/360004683552-Integrate-ChurnZero-using-Javascript + * @param {object} pluginConfig - Plugin settings + * @param {string} pluginConfig.appKey - ChurnZero AppKey + * @param {string} pluginConfig.subdomain - ChurnZero AppKey + * @param {string} pluginConfig.whitelistedEvents - An optional list of events to track + * @return {AnalyticsPlugin} + * @example + * + * This will load ChurnZero on to the page + * churnZeroPlugin({ + * appKey: '1234578' + * subdomain: 'mycompanydomain' + * }) + */ +function churnZeroPlugin() { + var pluginConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + return { + name: 'churn-zero', + config: pluginConfig, + initialize: function initialize(_ref) { + var config = _ref.config; + var appKey = config.appKey, + subdomain = config.subdomain; + if (!appKey) { + throw new Error('No ChurnZero appKey defined'); + } + if (!subdomain) { + throw new Error('No ChurnZero subdomain defined'); + } + + // Create script & append to DOM + var script = document.createElement('script'); + var firstScript = document.getElementsByTagName('script')[0]; + script.type = 'text/javascript'; + script.async = true; + script.src = "https://".concat(subdomain, ".churnzero.net/churnzero.js"); + firstScript.parentNode.insertBefore(script, firstScript); + }, + identify: function identify(_ref2) { + var payload = _ref2.payload, + config = _ref2.config; + var _payload$traits = payload.traits, + company = _payload$traits.company, + email = _payload$traits.email, + name = _payload$traits.name, + firstName = _payload$traits.firstName, + lastName = _payload$traits.lastName; + if (typeof ChurnZero === 'undefined') return; + if (config.appKey) { + ChurnZero.push(['setAppKey', config.appKey]); + } + if (company && company.id && email) { + ChurnZero.push(['setContact', company.id, email]); + } + if (name) { + ChurnZero.push(['setAttribute', 'account', 'Name', name]); + } + if (firstName) { + ChurnZero.push(['setAttribute', 'contact', 'FirstName', firstName]); + } + if (lastName) { + ChurnZero.push(['setAttribute', 'contact', 'LastName', lastName]); + } + if (email) { + ChurnZero.push(['setAttribute', 'contact', 'Email', email]); + } + }, + track: function track(_ref3) { + var payload = _ref3.payload, + config = _ref3.config; + if (typeof ChurnZero === 'undefined') return; + if (config.whitelistedEvents && !config.whitelistedEvents.includes(payload.event)) return; + ChurnZero.push(['trackEvent', payload.event, undefined, undefined, payload.properties]); + }, + loaded: function loaded() { + return !!window.ChurnZero; + } + }; +} + +/* This module will shake out unused code and work in browser and node 🎉 */ +var index = churnZeroPlugin ; + +module.exports = index; diff --git a/packages/analytics-plugin-churn-zero/lib/analytics-plugin-churn-zero.browser.es.js b/packages/analytics-plugin-churn-zero/lib/analytics-plugin-churn-zero.browser.es.js new file mode 100644 index 00000000..7a3a131f --- /dev/null +++ b/packages/analytics-plugin-churn-zero/lib/analytics-plugin-churn-zero.browser.es.js @@ -0,0 +1,91 @@ +import 'unfetch'; + +/* global ChurnZero */ + +/** + * ChurnZero plugin + * @link https://getanalytics.io/plugins/churn-zero + * @link https://support.churnzero.com/hc/en-us/articles/360004683552-Integrate-ChurnZero-using-Javascript + * @param {object} pluginConfig - Plugin settings + * @param {string} pluginConfig.appKey - ChurnZero AppKey + * @param {string} pluginConfig.subdomain - ChurnZero AppKey + * @param {string} pluginConfig.whitelistedEvents - An optional list of events to track + * @return {AnalyticsPlugin} + * @example + * + * This will load ChurnZero on to the page + * churnZeroPlugin({ + * appKey: '1234578' + * subdomain: 'mycompanydomain' + * }) + */ +function churnZeroPlugin() { + var pluginConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + return { + name: 'churn-zero', + config: pluginConfig, + initialize: function initialize(_ref) { + var config = _ref.config; + var appKey = config.appKey, + subdomain = config.subdomain; + if (!appKey) { + throw new Error('No ChurnZero appKey defined'); + } + if (!subdomain) { + throw new Error('No ChurnZero subdomain defined'); + } + + // Create script & append to DOM + var script = document.createElement('script'); + var firstScript = document.getElementsByTagName('script')[0]; + script.type = 'text/javascript'; + script.async = true; + script.src = "https://".concat(subdomain, ".churnzero.net/churnzero.js"); + firstScript.parentNode.insertBefore(script, firstScript); + }, + identify: function identify(_ref2) { + var payload = _ref2.payload, + config = _ref2.config; + var _payload$traits = payload.traits, + company = _payload$traits.company, + email = _payload$traits.email, + name = _payload$traits.name, + firstName = _payload$traits.firstName, + lastName = _payload$traits.lastName; + if (typeof ChurnZero === 'undefined') return; + if (config.appKey) { + ChurnZero.push(['setAppKey', config.appKey]); + } + if (company && company.id && email) { + ChurnZero.push(['setContact', company.id, email]); + } + if (name) { + ChurnZero.push(['setAttribute', 'account', 'Name', name]); + } + if (firstName) { + ChurnZero.push(['setAttribute', 'contact', 'FirstName', firstName]); + } + if (lastName) { + ChurnZero.push(['setAttribute', 'contact', 'LastName', lastName]); + } + if (email) { + ChurnZero.push(['setAttribute', 'contact', 'Email', email]); + } + }, + track: function track(_ref3) { + var payload = _ref3.payload, + config = _ref3.config; + if (typeof ChurnZero === 'undefined') return; + if (config.whitelistedEvents && !config.whitelistedEvents.includes(payload.event)) return; + ChurnZero.push(['trackEvent', payload.event, undefined, undefined, payload.properties]); + }, + loaded: function loaded() { + return !!window.ChurnZero; + } + }; +} + +/* This module will shake out unused code and work in browser and node 🎉 */ +var index = churnZeroPlugin ; + +export { index as default }; diff --git a/packages/analytics-plugin-churn-zero/lib/analytics-plugin-churn-zero.cjs.js b/packages/analytics-plugin-churn-zero/lib/analytics-plugin-churn-zero.cjs.js new file mode 100644 index 00000000..1fc57383 --- /dev/null +++ b/packages/analytics-plugin-churn-zero/lib/analytics-plugin-churn-zero.cjs.js @@ -0,0 +1,112 @@ +'use strict'; + +var fetch = require('unfetch'); + +function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } + +var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch); + +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } +function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } +function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } +function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } +function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } + +/** + * Custify server plugin + * @link https://getanalytics.io/plugins/churn-zero + * @link https://docs.churn-zero.com/ + * @param {object} pluginConfig - Plugin settings + * @param {string} pluginConfig.appKey - ChurnZero API key + * @param {string} pluginConfig.subdomain - ChurnZero AppKey + * @param {string} pluginConfig.whitelistedEvents - An optional list of events to track + * @return {AnalyticsPlugin} + * @example + * + * churnZeroPlugin({ + * appKey: '1234578' + * subdomain: 'mycompanydomain' + * }) + */ +function churnZeroPlugin(_ref) { + var appKey = _ref.appKey, + subdomain = _ref.subdomain, + accountExternalId = _ref.accountExternalId, + contactExternalId = _ref.contactExternalId; + var _loaded = false; + return { + name: 'churn-zero', + config: { + appKey: appKey, + subdomain: subdomain, + accountExternalId: accountExternalId, + contactExternalId: contactExternalId + }, + track: function track(_ref2) { + var payload = _ref2.payload; + var _payload$traits = payload.traits, + company = _payload$traits.company, + email = _payload$traits.email, + event = _payload$traits.event, + properties = _payload$traits.properties; + makeChurnZeroRequest(config, { + action: 'trackEvent', + eventName: event, + cf_metadata: properties, + accountExternalId: company ? company.id : undefined, + contactExternalId: email + }); + }, + identify: function identify(_ref3) { + var payload = _ref3.payload; + var _payload$traits2 = payload.traits, + company = _payload$traits2.company, + email = _payload$traits2.email, + name = _payload$traits2.name, + firstName = _payload$traits2.firstName, + lastName = _payload$traits2.lastName; + makeChurnZeroRequest(config, { + action: 'setAttribute', + entity: 'account', + attr_Name: name, + accountExternalId: company.id, + contactExternalId: email + }); + makeChurnZeroRequest(config, { + action: 'setAttribute', + entity: 'contact', + attr_FirstName: firstName, + attr_LastName: lastName, + attr_Email: email, + accountExternalId: company.id, + contactExternalId: email + }); + }, + loaded: function loaded() { + return _loaded; + } + }; +} +function makeChurnZeroRequest(_ref4) { + var config = _ref4.config, + body = _ref4.body; + return fetch__default["default"]("https://".concat(config.subdomain, ".churnzero.net/i"), { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Cache-Control': 'no-cache' + }, + body: JSON.stringify(_objectSpread(_objectSpread({ + appKey: config.appKey + }, body), {}, { + accountExternalId: body.accountExternalId || config.accountExternalId, + contactExternalId: body.contactExternalId || config.contactExternalId + })) + }); +} + +/* This module will shake out unused code and work in browser and node 🎉 */ +var index = churnZeroPlugin; + +module.exports = index; diff --git a/packages/analytics-plugin-churn-zero/lib/analytics-plugin-churn-zero.es.js b/packages/analytics-plugin-churn-zero/lib/analytics-plugin-churn-zero.es.js new file mode 100644 index 00000000..908f9e64 --- /dev/null +++ b/packages/analytics-plugin-churn-zero/lib/analytics-plugin-churn-zero.es.js @@ -0,0 +1,106 @@ +import fetch from 'unfetch'; + +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } +function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } +function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } +function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } +function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } + +/** + * Custify server plugin + * @link https://getanalytics.io/plugins/churn-zero + * @link https://docs.churn-zero.com/ + * @param {object} pluginConfig - Plugin settings + * @param {string} pluginConfig.appKey - ChurnZero API key + * @param {string} pluginConfig.subdomain - ChurnZero AppKey + * @param {string} pluginConfig.whitelistedEvents - An optional list of events to track + * @return {AnalyticsPlugin} + * @example + * + * churnZeroPlugin({ + * appKey: '1234578' + * subdomain: 'mycompanydomain' + * }) + */ +function churnZeroPlugin(_ref) { + var appKey = _ref.appKey, + subdomain = _ref.subdomain, + accountExternalId = _ref.accountExternalId, + contactExternalId = _ref.contactExternalId; + var _loaded = false; + return { + name: 'churn-zero', + config: { + appKey: appKey, + subdomain: subdomain, + accountExternalId: accountExternalId, + contactExternalId: contactExternalId + }, + track: function track(_ref2) { + var payload = _ref2.payload; + var _payload$traits = payload.traits, + company = _payload$traits.company, + email = _payload$traits.email, + event = _payload$traits.event, + properties = _payload$traits.properties; + makeChurnZeroRequest(config, { + action: 'trackEvent', + eventName: event, + cf_metadata: properties, + accountExternalId: company ? company.id : undefined, + contactExternalId: email + }); + }, + identify: function identify(_ref3) { + var payload = _ref3.payload; + var _payload$traits2 = payload.traits, + company = _payload$traits2.company, + email = _payload$traits2.email, + name = _payload$traits2.name, + firstName = _payload$traits2.firstName, + lastName = _payload$traits2.lastName; + makeChurnZeroRequest(config, { + action: 'setAttribute', + entity: 'account', + attr_Name: name, + accountExternalId: company.id, + contactExternalId: email + }); + makeChurnZeroRequest(config, { + action: 'setAttribute', + entity: 'contact', + attr_FirstName: firstName, + attr_LastName: lastName, + attr_Email: email, + accountExternalId: company.id, + contactExternalId: email + }); + }, + loaded: function loaded() { + return _loaded; + } + }; +} +function makeChurnZeroRequest(_ref4) { + var config = _ref4.config, + body = _ref4.body; + return fetch("https://".concat(config.subdomain, ".churnzero.net/i"), { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Cache-Control': 'no-cache' + }, + body: JSON.stringify(_objectSpread(_objectSpread({ + appKey: config.appKey + }, body), {}, { + accountExternalId: body.accountExternalId || config.accountExternalId, + contactExternalId: body.contactExternalId || config.contactExternalId + })) + }); +} + +/* This module will shake out unused code and work in browser and node 🎉 */ +var index = churnZeroPlugin; + +export { index as default };