Skip to content

Commit

Permalink
review comment addressed for initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Sep 16, 2021
1 parent b6ec6bd commit cfb668c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 23 deletions.
34 changes: 11 additions & 23 deletions integrations/Sentry/browser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable no-unused-expressions */

import logger from "../../utils/logUtil";
import ScriptLoader from "../ScriptLoader";
import {SentryScriptLoader, identifierPayloadBuilder} from "./utils";
import {getDefinedTraits} from "../../utils/utils";


class Sentry {
Expand All @@ -25,12 +26,10 @@ class Sentry {
logger.debug("DSN is a mandatory field");
return;
}
ScriptLoader(
SentryScriptLoader(
"Sentry",
`https://browser.sentry-cdn.com/6.12.0/bundle.min.js`
);
integrity="sha384-S3qfdh3AsT1UN84WIYNuOX9vVOoFg3nB17Jp5/pTFGDBGBt+dtz7MGAV845efkZr"
crossorigin="anonymous"

window.Sentry = {
dsn: this.dsn,
Expand All @@ -49,38 +48,27 @@ class Sentry {
// eslint-disable-next-line class-methods-use-this
isLoaded() {
logger.debug("===in Sentry isLoaded===");
return !!(window.Sentry && window.Sentry.push !== Array.prototype.push);
return !!(window.Sentry && window.Sentry.setUser !== Array.prototype.push);
}

// eslint-disable-next-line class-methods-use-this
isReady() {
logger.debug("===in Sentry isReady===");
return !!(window.criteo_q && window.Sentry.push !== Array.prototype.push);
return !!(window.Sentry && window.Sentry.setUser !== Array.prototype.push);
}

Identify(rudderElement) {
identify(rudderElement) {
const { traits } = rudderElement.message;
const { userId, email, name } = getDefinedTraits(message); // userId sent as id and username sent as name
const { userId, email, name } = getDefinedTraits(rudderElement.message); // userId sent as id and username sent as name
const ip_address = get (message,"traits.ip_address") || get (message,"context.traits.ip_address");
const userIdentificationProperty = ["userId", "email" , "name", "ip_address"]


if( ! userId && ! email && ! name && ! ip_address ) { // if no user identification property is present the event will be dropped
logger.debug("Any one of userId, email, name and ip_address is mandatory");
return;
}
const userIdentifierPayload = {};
if (userId) {
userIdentifierPayload.id = userId;
}
if(email) {
userIdentifierPayload.email = email;
}
if(name) {
userIdentifierPayload.username = name;
}
if(ip_address) {
userIdentifierPayload.ip_address = ip_address;
}

const userIdentifierPayload = identifierPayloadBuilder (userId, email, name, ip_address);

const finalPayload = {
... userIdentifierPayload,
...traits
Expand Down
35 changes: 35 additions & 0 deletions integrations/Sentry/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import logger from "../../utils/logUtil";

const SentryScriptLoader = (id, src) => {
logger.debug(`in script loader=== ${id}`);
const js = document.createElement("script");
js.src = src;
js.integrity = "sha384-S3qfdh3AsT1UN84WIYNuOX9vVOoFg3nB17Jp5/pTFGDBGBt+dtz7MGAV845efkZr";
js.crossorigin = "anonymous"
js.async = true;
js.type = "text/javascript";
js.id = id;
const e = document.getElementsByTagName("script")[0];
logger.debug("==parent script==", e);
logger.debug("==adding script==", js);
e.parentNode.insertBefore(js, e);
};

const identifierPayloadBuilder = (userId, email, name, ip_address) => {
payload = {};
if (userId) {
userIdentifierPayload.id = userId;
}
if(email) {
userIdentifierPayload.email = email;
}
if(name) {
userIdentifierPayload.username = name;
}
if(ip_address) {
userIdentifierPayload.ip_address = ip_address;
}
return payload;
};

export {SentryScriptLoader, identifierPayloadBuilder};

0 comments on commit cfb668c

Please sign in to comment.