@ravti/analytics
Advanced tools
Comparing version
@@ -7,2 +7,6 @@ const presets = [ | ||
module.exports = { presets }; | ||
const plugins = [ | ||
"@babel/plugin-proposal-export-default-from", | ||
]; | ||
module.exports = { presets, plugins }; |
"use strict"; | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _integrations = require("./integrations"); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -11,388 +16,2 @@ | ||
/* global window */ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable no-bitwise */ | ||
/* eslint-disable consistent-return */ | ||
var Immutable = require("immutable"); | ||
var moment = require("moment"); | ||
var numeral = require("numeral"); | ||
var LogRocket = require("logrocket"); | ||
var _require = require("./constants"), | ||
GROUPS = _require.GROUPS, | ||
INTERCOM_APP_ID = _require.INTERCOM_APP_ID, | ||
VISITED_URL = _require.VISITED_URL, | ||
LOGROCKET_PROJECT_ID = _require.LOGROCKET_PROJECT_ID; | ||
var RAVTI_ORGANIZATION_DEFINITION = { | ||
id: "RAVTI-ORGANIZATION__00000000", | ||
name: "Ravti", | ||
created_at: "2014-08-14T13:33:37+00:00" | ||
}; | ||
var IntercomAnalytics = | ||
/*#__PURE__*/ | ||
function () { | ||
function IntercomAnalytics() { | ||
_classCallCheck(this, IntercomAnalytics); | ||
} | ||
_createClass(IntercomAnalytics, null, [{ | ||
key: "_raw", | ||
value: function _raw(_ref) { | ||
var _ref$event = _ref.event, | ||
event = _ref$event === void 0 ? "" : _ref$event, | ||
_ref$eventTag = _ref.eventTag, | ||
eventTag = _ref$eventTag === void 0 ? "" : _ref$eventTag, | ||
_ref$metadata = _ref.metadata, | ||
metadata = _ref$metadata === void 0 ? {} : _ref$metadata; | ||
if (window && window.Intercom) { | ||
if (eventTag) { | ||
window.Intercom(event, eventTag, metadata); | ||
return; | ||
} | ||
window.Intercom(event, metadata); | ||
} | ||
} | ||
}, { | ||
key: "start", | ||
value: function start(user, userType) { | ||
IntercomAnalytics._raw({ | ||
event: "boot", | ||
metadata: IntercomAnalytics.transformUser(user, userType) | ||
}); | ||
} | ||
}, { | ||
key: "stop", | ||
value: function stop() { | ||
IntercomAnalytics._raw({ | ||
event: "shutdown" | ||
}); | ||
} | ||
}, { | ||
key: "track", | ||
value: function track(_ref2) { | ||
var key = _ref2.key, | ||
metadata = _ref2.metadata; | ||
IntercomAnalytics._raw({ | ||
event: "trackEvent", | ||
eventTag: key, | ||
metadata: metadata | ||
}); | ||
} | ||
}, { | ||
key: "transformUserOrganization", | ||
value: function transformUserOrganization(user) { | ||
if (!user) { | ||
console.warn("Cannot transform undefined user"); | ||
return null; | ||
} | ||
var isAdmin = user.get("group_memberships") & GROUPS.GOD; | ||
if (isAdmin) { | ||
return { | ||
company_id: RAVTI_ORGANIZATION_DEFINITION.id, | ||
id: RAVTI_ORGANIZATION_DEFINITION.id, | ||
name: RAVTI_ORGANIZATION_DEFINITION.name, | ||
created_at: RAVTI_ORGANIZATION_DEFINITION.created_at | ||
}; | ||
} | ||
var organization = user.get("organization"); | ||
if (!organization) { | ||
console.warn("User does not have an organization defined", user); | ||
return null; | ||
} | ||
return { | ||
id: organization.get("id"), | ||
name: organization.get("name"), | ||
created_at: organization.get("created_at") | ||
}; | ||
} | ||
}, { | ||
key: "transformUser", | ||
value: function transformUser(user, userType) { | ||
if (!user) { | ||
console.warn("Cannot transform undefined user"); | ||
return { | ||
app_id: INTERCOM_APP_ID | ||
}; | ||
} | ||
var userData = Immutable.Map.isMap(user) ? user : Immutable.fromJS(user); // TODO Revisit the keys that we send here | ||
return { | ||
app_id: INTERCOM_APP_ID, | ||
email: userData.get("email"), | ||
group_memberships: userData.get("group_memberships"), | ||
name: userData.get("name", null) || "".concat(userData.get("first_name"), " ").concat(userData.get("last_name")), | ||
phone: userData.get("phone_number", null) || userData.get("phone", null), | ||
user_id: userData.get("id"), | ||
user_type: userType, | ||
created_at: moment.utc(userData.get("created_at")).unix(), | ||
company: IntercomAnalytics.transformUserOrganization(userData) | ||
}; | ||
} | ||
}]); | ||
return IntercomAnalytics; | ||
}(); | ||
var SegmentAnalytics = | ||
/*#__PURE__*/ | ||
function () { | ||
function SegmentAnalytics() { | ||
_classCallCheck(this, SegmentAnalytics); | ||
} | ||
_createClass(SegmentAnalytics, null, [{ | ||
key: "_raw", | ||
value: function _raw(type, event, properties) { | ||
if (window && window.analytics) { | ||
if (type === "track") { | ||
if (event === VISITED_URL && properties && properties.url) { | ||
return window.analytics.page(properties.url); | ||
} | ||
return window.analytics.track(event, properties); | ||
} | ||
if (type === "identify") { | ||
var rv = window.analytics.identify(event, properties); // Associate LogRocket callback for session URL in Segment | ||
// https://docs.logrocket.com/docs/supporting-users | ||
LogRocket.getSessionURL(function (sessionURL) { | ||
window.analytics.track("LogRocket", { | ||
sessionURL: sessionURL | ||
}); | ||
}); | ||
return rv; | ||
} | ||
console.warn("Don't know how to handle event of type \"".concat(event, "\", not tracking")); | ||
return false; | ||
} | ||
console.warn("Attempted to track event in Segment without loading library " + "propertly in the `window`"); | ||
} | ||
}, { | ||
key: "getUserId", | ||
value: function getUserId(user, userType) { | ||
var userId = Immutable.Map.isMap(user) ? user.get("id") : (user || {}).id; | ||
switch (userType) { | ||
case "user": | ||
return "RAVTI-USER__".concat(numeral(userId).format("00000000")); | ||
case "tenant": | ||
return "RAVTI-TENANT__".concat(numeral(userId).format("00000000")); | ||
case "vendor": | ||
return "RAVTI-VENDOR__".concat(numeral(userId).format("00000000")); | ||
default: | ||
throw new Error("Unknown user type \"".concat(userType, "\"")); | ||
} | ||
} | ||
}, { | ||
key: "start", | ||
value: function start(user, userType) { | ||
if (!user) { | ||
console.warn("Cannot init Segment without a user, exiting"); | ||
return; | ||
} | ||
var userData = Immutable.Map.isMap(user) ? user : Immutable.fromJS(user); | ||
var segmentUserId = SegmentAnalytics.getUserId(userData, userType); | ||
var metadata = { | ||
firstName: userData.get("first_name"), | ||
lastName: userData.get("last_name"), | ||
createdAt: userData.get("created_at"), | ||
email: userData.get("email"), | ||
phone: userData.get("phone_number"), | ||
username: userData.get("email"), | ||
user_id: userData.get("id"), | ||
user_type: userType, | ||
group_memberships: userData.get("group_memberships"), | ||
company: SegmentAnalytics.transformUserOrganization(userData) | ||
}; | ||
return SegmentAnalytics._raw("identify", segmentUserId, metadata); | ||
} | ||
}, { | ||
key: "stop", | ||
value: function stop() {// noop | ||
} | ||
}, { | ||
key: "track", | ||
value: function track(_ref3) { | ||
var key = _ref3.key, | ||
metadata = _ref3.metadata; | ||
SegmentAnalytics._raw("track", key, metadata); | ||
} | ||
}, { | ||
key: "transformUserOrganization", | ||
value: function transformUserOrganization(user) { | ||
if (!user) { | ||
console.warn("Cannot init Segment without a user, exiting"); | ||
return null; | ||
} | ||
var isAdmin = user.get("group_memberships") & GROUPS.GOD; | ||
if (isAdmin) { | ||
return RAVTI_ORGANIZATION_DEFINITION; | ||
} | ||
var organization = user.get("organization"); | ||
if (!organization) { | ||
console.warn("User does not have an organization defined", user); | ||
return null; | ||
} | ||
var segmentCompanyId = "RAVTI-ORGANIZATION__".concat(numeral(organization.get("id")).format("00000000")); | ||
return { | ||
id: segmentCompanyId, | ||
name: organization.get("name"), | ||
created_at: organization.get("created_at") | ||
}; | ||
} | ||
}]); | ||
return SegmentAnalytics; | ||
}(); | ||
var LogRocketAnalytics = | ||
/*#__PURE__*/ | ||
function () { | ||
function LogRocketAnalytics() { | ||
_classCallCheck(this, LogRocketAnalytics); | ||
} | ||
_createClass(LogRocketAnalytics, null, [{ | ||
key: "getUserId", | ||
value: function getUserId(user, userType) { | ||
var userId = Immutable.Map.isMap(user) ? user.get("id") : (user || {}).id; | ||
switch (userType) { | ||
case "user": | ||
return "RAVTI-USER__".concat(numeral(userId).format("00000000")); | ||
case "tenant": | ||
return "RAVTI-TENANT__".concat(numeral(userId).format("00000000")); | ||
case "vendor": | ||
return "RAVTI-VENDOR__".concat(numeral(userId).format("00000000")); | ||
default: | ||
throw new Error("Unknown user type \"".concat(userType, "\"")); | ||
} | ||
} | ||
}, { | ||
key: "transformUserOrganization", | ||
value: function transformUserOrganization(user) { | ||
if (!user) { | ||
console.warn("Cannot init LogRocket without a user, exiting"); | ||
return null; | ||
} | ||
var isAdmin = user.get("group_memberships") & GROUPS.GOD; | ||
if (isAdmin) { | ||
return RAVTI_ORGANIZATION_DEFINITION; | ||
} | ||
var organization = user.get("organization"); | ||
if (!organization) { | ||
console.warn("User does not have an organization defined", user); | ||
return null; | ||
} | ||
var logrocketCompanyId = "RAVTI-ORGANIZATION__".concat(numeral(organization.get("id")).format("00000000")); | ||
return { | ||
id: logrocketCompanyId, | ||
name: organization.get("name"), | ||
created_at: organization.get("created_at") | ||
}; | ||
} | ||
}, { | ||
key: "start", | ||
value: function start(user, userType) { | ||
/* | ||
* There's a chance that we don't not need this | ||
* - @jmfurlott, 2019-01-29 12:01 EST | ||
* - @woodb, 2019-01-29 12:02 EST | ||
*/ | ||
/* | ||
const isAdmin = user.get("group_memberships") & GROUPS.GOD; | ||
if (isAdmin) { | ||
console.warn("Admin users are excluded from LogRocket"); | ||
return; | ||
} | ||
*/ | ||
LogRocket.init(LOGROCKET_PROJECT_ID); | ||
var userData = Immutable.Map.isMap(user) ? user : Immutable.fromJS(user); | ||
LogRocket.identify(LogRocketAnalytics.getUserId(user, userType), { | ||
name: [userData.get("first_name"), userData.get("last_name")].join(" "), | ||
createdAt: userData.get("created_at"), | ||
email: userData.get("email"), | ||
phone: userData.get("phone_number"), | ||
username: userData.get("email"), | ||
user_id: userData.get("id"), | ||
user_type: userType, | ||
group_memberships: userData.get("group_memberships"), | ||
company: LogRocketAnalytics.transformUserOrganization(userData) | ||
}); | ||
} | ||
}, { | ||
key: "stop", | ||
value: function stop() { | ||
console.debug("LogRocket noop: stop called"); | ||
} | ||
}, { | ||
key: "track", | ||
value: function track(_ref4) { | ||
var key = _ref4.key, | ||
metadata = _ref4.metadata; | ||
try { | ||
var eventString = JSON.stringify({ | ||
key: key, | ||
metadata: metadata | ||
}, null, 2); | ||
LogRocket.track(eventString); | ||
} catch (err) { | ||
// Let the console know but swallow the error so that we don't halt | ||
// execution b/c we couldn't represent the payload as a JSON string | ||
// | ||
// https://docs.logrocket.com/reference#track | ||
console.warn("Error while trying to track the event \"".concat(key, "\" to LogRocket"), err); | ||
if (typeof key === "string" || key instanceof String) { | ||
LogRocket.track(key); | ||
} else { | ||
console.debug("Could not track event to LogRocket with type ".concat(_typeof(key))); | ||
} | ||
} | ||
} | ||
}]); | ||
return LogRocketAnalytics; | ||
}(); | ||
var RavtiAnalytics = | ||
@@ -406,20 +25,10 @@ /*#__PURE__*/ | ||
_createClass(RavtiAnalytics, null, [{ | ||
key: "reduxMiddleware", | ||
value: function reduxMiddleware() { | ||
// If we ever need to add more middlewares for analytical purposes we can | ||
// do this here... this at least sets the stage for us to have this | ||
// consolidated in one place... also, in the future, we could consider | ||
// using some of the sanitation features in the LogRocket middleware | ||
// stuff... | ||
// | ||
// https://docs.logrocket.com/reference#redux-logging | ||
return LogRocket.reduxMiddleware(); | ||
} | ||
}, { | ||
key: "start", | ||
value: function start(user, userType) { | ||
try { | ||
IntercomAnalytics.start(user, userType); | ||
SegmentAnalytics.start(user, userType); | ||
LogRocketAnalytics.start(user, userType); | ||
_integrations.IntercomAnalytics.start(user, userType); | ||
_integrations.SegmentAnalytics.start(user, userType); | ||
_integrations.LogRocketAnalytics.start(user, userType); | ||
} catch (err) { | ||
@@ -433,5 +42,7 @@ console.error(err); | ||
try { | ||
IntercomAnalytics.stop(); | ||
SegmentAnalytics.stop(); | ||
LogRocketAnalytics.stop(); | ||
_integrations.IntercomAnalytics.stop(); | ||
_integrations.SegmentAnalytics.stop(); | ||
_integrations.LogRocketAnalytics.stop(); | ||
} catch (err) { | ||
@@ -443,16 +54,18 @@ console.error(err); | ||
key: "track", | ||
value: function track(_ref5) { | ||
var key = _ref5.key, | ||
metadata = _ref5.metadata; | ||
value: function track(_ref) { | ||
var key = _ref.key, | ||
metadata = _ref.metadata; | ||
try { | ||
IntercomAnalytics.track({ | ||
_integrations.IntercomAnalytics.track({ | ||
key: key, | ||
metadata: metadata | ||
}); | ||
SegmentAnalytics.track({ | ||
_integrations.SegmentAnalytics.track({ | ||
key: key, | ||
metadata: metadata | ||
}); | ||
LogRocketAnalytics.track({ | ||
_integrations.LogRocketAnalytics.track({ | ||
key: key, | ||
@@ -470,2 +83,2 @@ metadata: metadata | ||
module.exports = RavtiAnalytics; | ||
exports.default = RavtiAnalytics; |
@@ -14,2 +14,7 @@ "use strict"; | ||
}; | ||
var RAVTI_ORGANIZATION_DEFINITION = { | ||
id: "RAVTI-ORGANIZATION__00000000", | ||
name: "Ravti", | ||
created_at: "2014-08-14T13:33:37+00:00" | ||
}; | ||
var EVENTS = { | ||
@@ -19,28 +24,30 @@ GROUPS: GROUPS, | ||
LOGROCKET_PROJECT_ID: LOGROCKET_PROJECT_ID, | ||
RAVTI_ORGANIZATION_DEFINITION: RAVTI_ORGANIZATION_DEFINITION, | ||
/* eventTag for core/client */ | ||
APPROVED_QUOTE: "approved-quote", | ||
CALC_ESTIMATED_REPLACEMENT: "calc-estimated-replacement", | ||
CHANGED_BUILDING_UNIT: "changed-building-unit", | ||
CHANGED_ORGANIZATION_NAME: "changed-organization-name", | ||
USER_ERROR_500_PAGE_DISPLAYED: "user-error-500-page-displayed", | ||
USER_ERROR_FORM_BAD_API_RESPONSE: "user-error-form-bad-api-response", | ||
USER_TOGGLED_GRID_DASHBOARD: "user-toggled-grid-dashboard", | ||
USER_TOGGLED_MAP_DASHBOARD: "user-toggled-map-dashboard", | ||
USER_VIEWED_CHANGELOG: "user-viewed-changelog", | ||
USER_VIEWED_COMPLIANCE_PDF: "user-viewed-compliance-pdf", | ||
USER_VIEWED_PROPOSAL_PDF: "user-viewed-proposal-pdf", | ||
VISITED_URL: "visited-url", | ||
CHANGED_ORGANIZATION_NAME: "changed-organization-name", | ||
CALC_ESTIMATED_REPLACEMENT: "calc-estimated-replacement", | ||
CHANGED_BUILDING_UNIT: "changed-building-unit", | ||
USER_VIEWED_PROPOSAL_PDF: "user-viewed-proposal-pdf", | ||
APPROVED_QUOTE: "approved-quote", | ||
USER_VIEWED_COMPLIANCE_PDF: "user-viewed-compliance-pdf", | ||
WORK_REQUEST_ERROR: "work-request-error", | ||
WORK_REQUEST_OPENED: "work-request-opened", | ||
WORK_REQUEST_SUBMITTED: "work-request-submitted", | ||
WORK_REQUEST_VIEWED_PROPOSAL: "work-request-viewed-proposal", | ||
WORK_REQUEST_ERROR: "work-request-error", | ||
USER_TOGGLED_GRID_DASHBOARD: "user-toggled-grid-dashboard", | ||
USER_TOGGLED_MAP_DASHBOARD: "user-toggled-map-dashboard", | ||
/* eventTag for compliance/client */ | ||
USER_TOGGLED_TC_ENABLED: "user-toggled-tc_enabled", | ||
TENANT_REQUESTED_ENROLLMENT: "tenant-requested-enrollment", | ||
TENANT_UPLOADED_DOC_ERROR: "tenant-uploaded-doc-error", | ||
TENANT_UPLOADED_DOC_SUCCESS: "tenant-uploaded-doc-success", | ||
TENANT_VISITED_COMPLIANCE: "tenant-visited-compliance", | ||
TENANT_VISITED_ENROLLMENT: "tenant-visited-enrollment", | ||
TENANT_VISITED_COMPLIANCE: "tenant-visited-compliance", | ||
TENANT_UPLOADED_DOC_SUCCESS: "tenant-uploaded-doc-success", | ||
TENANT_UPLOADED_DOC_ERROR: "tenant-uploaded-doc-error" | ||
USER_TOGGLED_TC_ENABLED: "user-toggled-tc_enabled" | ||
}; | ||
module.exports = EVENTS; |
{ | ||
"name": "@ravti/analytics", | ||
"version": "21.6.1", | ||
"version": "21.6.2-beta.0", | ||
"description": "Ravti analytics", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"format": "`npm bin`/prettier --write 'src/**/*js' && `npm bin`/eslint --fix src", | ||
"format": "`npm bin`/prettier --write 'src/**/*js' --write 'tests/**/*js' && `npm bin`/eslint --fix src tests", | ||
"prepublish": "npm run build", | ||
"build": "`npm bin`/babel src --out-dir lib", | ||
"test": "echo lol" | ||
"pretest": "npm run format", | ||
"test": "`npm bin`/jest" | ||
}, | ||
@@ -15,17 +16,20 @@ "author": "John Jung <john.jung@ravti.com>", | ||
"dependencies": { | ||
"@babel/polyfill": "^7.2.5", | ||
"immutable": "^4.0.0-rc.12", | ||
"logrocket": "^0.6.19", | ||
"moment": "^2.22.2", | ||
"numeral": "^2.0.6" | ||
"@babel/polyfill": "7.2.5", | ||
"immutable": "4.0.0-rc.12", | ||
"logrocket": "0.6.19", | ||
"moment": "2.24.0", | ||
"numeral": "2.0.6" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.2.3", | ||
"@babel/core": "^7.2.2", | ||
"@babel/preset-env": "^7.2.3", | ||
"babel-eslint": "^10.0.1", | ||
"eslint": "^5.9.0", | ||
"eslint-config-airbnb": "^17.1.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"prettier": "^1.15.2" | ||
"@babel/cli": "7.2.3", | ||
"@babel/core": "7.2.2", | ||
"@babel/plugin-proposal-export-default-from": "7.2.0", | ||
"@babel/preset-env": "7.3.1", | ||
"babel-eslint": "10.0.1", | ||
"babel-jest": "24.1.0", | ||
"eslint": "5.13.0", | ||
"eslint-config-airbnb": "17.1.0", | ||
"eslint-plugin-import": "2.16.0", | ||
"jest": "24.1.0", | ||
"prettier": "1.16.4" | ||
}, | ||
@@ -32,0 +36,0 @@ "repository": { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
32738
79.53%16
128.57%841
70.59%11
37.5%2
100%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated
Updated
Updated