Skip to content

Commit

Permalink
temporarily including compiled lib files
Browse files Browse the repository at this point in the history
  • Loading branch information
aonawale committed Aug 30, 2024
1 parent 10ede37 commit 393d346
Show file tree
Hide file tree
Showing 4 changed files with 402 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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 };
Original file line number Diff line number Diff line change
@@ -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;
Loading

0 comments on commit 393d346

Please sign in to comment.