@ravti/analytics
Advanced tools
Comparing version 21.5.2-rc3 to 21.5.2-rc4
"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); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -22,6 +24,9 @@ | ||
var LogRocket = require("logrocket"); | ||
var _require = require("./constants"), | ||
GROUPS = _require.GROUPS, | ||
INTERCOM_APP_ID = _require.INTERCOM_APP_ID, | ||
VISITED_URL = _require.VISITED_URL; | ||
VISITED_URL = _require.VISITED_URL, | ||
LOGROCKET_PROJECT_ID = _require.LOGROCKET_PROJECT_ID; | ||
@@ -265,2 +270,87 @@ var RAVTI_ORGANIZATION_DEFINITION = { | ||
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: "start", | ||
value: function start(user, userType) { | ||
var 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") | ||
}); | ||
} | ||
}, { | ||
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 = | ||
@@ -274,2 +364,14 @@ /*#__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", | ||
@@ -280,2 +382,3 @@ value: function start(user, userType) { | ||
SegmentAnalytics.start(user, userType); | ||
LogRocketAnalytics.start(user, userType); | ||
} catch (err) { | ||
@@ -291,2 +394,3 @@ console.error(err); | ||
SegmentAnalytics.stop(); | ||
LogRocketAnalytics.stop(); | ||
} catch (err) { | ||
@@ -298,5 +402,5 @@ console.error(err); | ||
key: "track", | ||
value: function track(_ref4) { | ||
var key = _ref4.key, | ||
metadata = _ref4.metadata; | ||
value: function track(_ref5) { | ||
var key = _ref5.key, | ||
metadata = _ref5.metadata; | ||
@@ -312,2 +416,6 @@ try { | ||
}); | ||
LogRocketAnalytics.track({ | ||
key: key, | ||
metadata: metadata | ||
}); | ||
} catch (err) { | ||
@@ -314,0 +422,0 @@ console.error(err); |
@@ -5,2 +5,3 @@ "use strict"; | ||
var INTERCOM_APP_ID = process.env.INTERCOM_APP_ID || process.env.REACT_APP_INTERCOM_APP_ID || "ohwetuz3"; | ||
var LOGROCKET_PROJECT_ID = process.env.LOGROCKET_PROJECT_ID || process.env.REACT_APP_LOGROCKET_PROJECT_ID || "krbiay/ravti-app-dev"; | ||
var GROUPS = { | ||
@@ -15,4 +16,5 @@ WHEEL: 32, | ||
var EVENTS = { | ||
GROUPS: GROUPS, | ||
INTERCOM_APP_ID: INTERCOM_APP_ID, | ||
GROUPS: GROUPS, | ||
LOGROCKET_PROJECT_ID: LOGROCKET_PROJECT_ID, | ||
@@ -19,0 +21,0 @@ /* eventTag for core/client */ |
{ | ||
"name": "@ravti/analytics", | ||
"version": "21.5.2-rc3", | ||
"version": "21.5.2-rc4", | ||
"description": "Ravti analytics", | ||
@@ -17,2 +17,3 @@ "main": "lib/index.js", | ||
"immutable": "^4.0.0-rc.12", | ||
"logrocket": "^0.6.19", | ||
"moment": "^2.22.2", | ||
@@ -19,0 +20,0 @@ "numeral": "^2.0.6" |
16764
454
5
+ Addedlogrocket@^0.6.19
+ Addedlogrocket@0.6.21(transitive)