Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
297a1a7
working on error reporting metrics
MoumitaM May 5, 2022
67a51f2
working on bugsnag integration
MoumitaM May 18, 2022
67f20d5
Update metrics/error-report/index.js
MoumitaM May 19, 2022
ea3c448
Update metrics/error-report/index.js
MoumitaM May 19, 2022
6cbebf2
Update metrics/error-report/index.js
MoumitaM May 19, 2022
17b2a35
working on Bugsnag integration
MoumitaM May 19, 2022
59d43f1
bugsnag module: releaseStage updated to production
MoumitaM May 19, 2022
394e34e
working on bugsnag
MoumitaM May 20, 2022
4ca1d06
Update metrics/error-report/index.js
MoumitaM May 23, 2022
713fab6
Update utils/utils.js
MoumitaM May 23, 2022
cbbecb2
bugsnag integration
MoumitaM May 23, 2022
5e74208
bugsnag integration
MoumitaM May 24, 2022
09f8550
fix: load Bugsnag by default
saikumarrs May 24, 2022
9bbe164
fix: immediately initialize Bugsnag client
saikumarrs May 24, 2022
3ac577f
fix: remove unnecessary return statements
saikumarrs May 24, 2022
33184c0
fix: bugsnag API key converted into a token to be replaced in CI
saikumarrs May 24, 2022
305ea8f
SDK meta data updated and comment added
MoumitaM May 25, 2022
babb2ea
updated bs configuration at initialisation
MoumitaM May 25, 2022
c041459
Update analytics.js
MoumitaM May 25, 2022
d2b8f04
refactor: in-place text substitution in buildspec files
saikumarrs May 25, 2022
a181070
misc updates in bugsnag integration
MoumitaM May 25, 2022
b8d8312
Merge branch 'feat.crashReportingMetrics' of github.com:rudderlabs/ru…
MoumitaM May 25, 2022
0bc5f1b
removed event type from error message and removed version from sdk me…
MoumitaM May 25, 2022
6c3a8b5
code cleaning
MoumitaM May 25, 2022
736a3f9
feat(ci): sourcemap files copied to S3
saikumarrs May 25, 2022
75011bb
Merge branch 'feat.crashReportingMetrics' of https://github.com/rudde…
saikumarrs May 25, 2022
964e383
Update analytics.js
MoumitaM May 25, 2022
21f4c70
Update analytics.js
MoumitaM May 25, 2022
3fa6c5d
Update analytics.js
MoumitaM May 25, 2022
d843ff5
Update analytics.js
MoumitaM May 25, 2022
43d3494
Update utils/utils.js
MoumitaM May 25, 2022
81cef53
Merge branch 'v1-staging' into feat.crashReportingMetrics
saikumarrs May 25, 2022
5b42ea4
refactor: reimported get method from utils
saikumarrs May 25, 2022
cd15090
replaced notifyError method with handleError
MoumitaM May 25, 2022
aa51924
Merge branch 'v1-staging' of github.com:rudderlabs/rudder-sdk-js into…
MoumitaM May 31, 2022
1318b6b
Bugsnag enhancements
MoumitaM Jun 2, 2022
8db9859
Update metrics/error-report/Bugsnag.js
MoumitaM Jun 3, 2022
012ce2e
Bugsnag refactoring
MoumitaM Jun 3, 2022
4c40ede
code refactoring
MoumitaM Jun 3, 2022
3b84e7a
fix(errors): refactored handleError method to block unwanted errors
saikumarrs Jun 3, 2022
f2c3f2f
Merge branch 'feat.crashReportingMetrics' of https://github.com/rudde…
saikumarrs Jun 3, 2022
7737d8e
Added 'Element.prototype.dataset' polyfill
saikumarrs Jun 3, 2022
707f0bc
Added 'loader' data attribute to script loader
saikumarrs Jun 3, 2022
37f4594
chore(update): Added script data attribute in all integrations
saikumarrs Jun 3, 2022
98cf8c3
fix: discard script errors not originating from SDK
saikumarrs Jun 3, 2022
82f9b32
updated ad-blocker script check condition
saikumarrs Jun 4, 2022
5e24dec
Discard all non-script loading errors
saikumarrs Jun 4, 2022
71f4f6f
Removed error message filter
saikumarrs Jun 4, 2022
93c7943
Removed unused variable
saikumarrs Jun 4, 2022
4a0a614
Fixed syntax issue
saikumarrs Jun 5, 2022
8a00882
fix: module type update
saikumarrs Jun 5, 2022
d14c815
fix: create new error object for script errors
saikumarrs Jun 5, 2022
e25e190
fix: setting event context
saikumarrs Jun 5, 2022
d31bfae
fix: used replacer function in JSON stringify
saikumarrs Jun 6, 2022
f4df49a
updated default initialisation behavior of bugsnag
MoumitaM Jun 8, 2022
6a94da3
Merge branch 'feat.crashReportingMetrics' of github.com:rudderlabs/ru…
MoumitaM Jun 8, 2022
167e727
updated code comment
MoumitaM Jun 8, 2022
08ac2c3
Merge branch 'v1-staging' of github.com:rudderlabs/rudder-sdk-js into…
MoumitaM Jun 9, 2022
7e9c23f
bugsnag config format modified
MoumitaM Jun 10, 2022
3665b54
Update analytics.js
MoumitaM Jun 11, 2022
d9f9aa9
code refactoring
MoumitaM Jun 11, 2022
04ab16c
Update utils/constants.js
MoumitaM Jun 13, 2022
e29cd62
code refactoring
MoumitaM Jun 13, 2022
2b3357a
Merge branch 'v1-staging' into feat.crashReportingMetrics
MoumitaM Jun 13, 2022
708be20
code refactoring
MoumitaM Jun 13, 2022
04c08c8
Merge branch 'feat.crashReportingMetrics' of github.com:rudderlabs/ru…
MoumitaM Jun 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 75 additions & 41 deletions analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getJSONTrimmed,
generateUUID,
handleError,
leaveBreadcrumb,
getDefaultPageProperties,
getUserProvidedConfigUrl,
findAllEnabledDestinations,
Expand All @@ -28,12 +29,15 @@ import {
getReferrer,
getReferringDomain,
commonNames,
get,
} from "./utils/utils";
import {
CONFIG_URL,
MAX_WAIT_FOR_INTEGRATION_LOAD,
INTEGRATION_LOAD_CHECK_INTERVAL,
POLYFILL_URL,
DEFAULT_ERROR_REPORT_PROVIDER,
ERROR_REPORT_PROVIDERS,
} from "./utils/constants";
import { integrations } from "./integrations";
import RudderElementBuilder from "./utils/RudderElementBuilder";
Expand All @@ -44,6 +48,7 @@ import { addDomEventHandlers } from "./utils/autotrack.js";
import ScriptLoader from "./integrations/ScriptLoader";
import parseLinker from "./utils/linker";
import CookieConsentFactory from "./cookieConsent/CookieConsentFactory";
import * as BugsnagLib from "./metrics/error-report/Bugsnag";

const queryDefaults = {
trait: "ajs_trait_",
Expand Down Expand Up @@ -167,6 +172,31 @@ class Analytics {
if (typeof response === "string") {
response = JSON.parse(response);
}

// Fetch Error reporting enable option from sourceConfig
const isErrorReportEnabled = get(
response.source.config,
"statsCollection.errorReports.enabled"
);

// Load Bugsnag only if it is enabled in the source config
if (isErrorReportEnabled === true) {
// Fetch the name of the Error reporter from sourceConfig
const provider = get(
response.source.config,
"statsCollection.errorReports.provider"
) || DEFAULT_ERROR_REPORT_PROVIDER;
if (!ERROR_REPORT_PROVIDERS.includes(provider)) {
logger.error("Invalid error reporting provider value");
}

if (provider === "bugsnag") {
// Load Bugsnag client SDK
BugsnagLib.load();
BugsnagLib.init(response.source.id);
}
}

if (
response.source.useAutoTracking &&
!this.autoTrackHandlersRegistered
Expand Down Expand Up @@ -194,15 +224,15 @@ class Analytics {
this.clientIntegrations
);

var cookieConsent;
let cookieConsent;
// Call the cookie consent factory to initialize and return the type of cookie
// consent being set. For now we only support OneTrust.
try {
cookieConsent = CookieConsentFactory.initialize(
this.cookieConsentOptions
);
} catch (e) {
logger.error(e);
handleError(e);
}

// If cookie consent object is return we filter according to consents given by user
Expand All @@ -214,7 +244,7 @@ class Analytics {
(cookieConsent && cookieConsent.isEnabled(intg.config)))
);
});

leaveBreadcrumb("Starting device-mode initialization");
this.init(this.clientIntegrations);
} catch (error) {
handleError(error);
Expand Down Expand Up @@ -254,21 +284,17 @@ class Analytics {
let intgInstance;
intgArray.forEach((intg) => {
try {
logger.debug(
"[Analytics] init :: trying to initialize integration name:: ",
intg.name
);
const msg = `[Analytics] init :: trying to initialize integration name:: ${intg.name}`;
logger.debug(msg);
leaveBreadcrumb(msg);
const intgClass = integrations[intg.name];
const destConfig = intg.config;
intgInstance = new intgClass(destConfig, self);
intgInstance.init();
logger.debug("initializing destination: ", intg);
this.isInitialized(intgInstance).then(this.replayEvents);
} catch (e) {
logger.error(
"[Analytics] initialize integration (integration.init()) failed :: ",
intg.name
);
handleError(e);
this.failedToBeLoadedIntegration.push(intgInstance);
}
});
Expand All @@ -289,6 +315,7 @@ class Analytics {
" failed loaded count: ",
object.failedToBeLoadedIntegration.length
);
leaveBreadcrumb(`Started replaying buffered events`);
// eslint-disable-next-line no-param-reassign
object.clientIntegrationObjects = [];
// eslint-disable-next-line no-param-reassign
Expand Down Expand Up @@ -412,6 +439,7 @@ class Analytics {
* @memberof Analytics
*/
page(category, name, properties, options, callback) {
leaveBreadcrumb(`Page event`);
if (!this.loaded) return;
if (typeof options === "function") (callback = options), (options = null);
if (typeof properties === "function")
Expand Down Expand Up @@ -444,6 +472,7 @@ class Analytics {
* @memberof Analytics
*/
track(event, properties, options, callback) {
leaveBreadcrumb(`Track event`);
if (!this.loaded) return;
if (typeof options === "function") (callback = options), (options = null);
if (typeof properties === "function")
Expand All @@ -462,6 +491,7 @@ class Analytics {
* @memberof Analytics
*/
identify(userId, traits, options, callback) {
leaveBreadcrumb(`Identify event`);
if (!this.loaded) return;
if (typeof options === "function") (callback = options), (options = null);
if (typeof traits === "function")
Expand All @@ -480,6 +510,7 @@ class Analytics {
* @param {*} callback
*/
alias(to, from, options, callback) {
leaveBreadcrumb(`Alias event`);
if (!this.loaded) return;
if (typeof options === "function") (callback = options), (options = null);
if (typeof from === "function")
Expand Down Expand Up @@ -507,6 +538,7 @@ class Analytics {
* @param {*} callback
*/
group(groupId, traits, options, callback) {
leaveBreadcrumb(`Group event`);
if (!this.loaded) return;
if (!arguments.length) return;

Expand Down Expand Up @@ -705,27 +737,27 @@ class Analytics {
// Blacklist is choosen for filtering events
case "blacklistedEvents":
if (Array.isArray(blacklistedEvents)) {
return blacklistedEvents.find(
(eventObj) =>
eventObj.eventName.trim().toUpperCase() === formattedEventName
) === undefined
? false
: true;
} else {
return false;
return (
blacklistedEvents.find(
(eventObj) =>
eventObj.eventName.trim().toUpperCase() === formattedEventName
) !== undefined
);
}
return false;

// Whitelist is choosen for filtering events
case "whitelistedEvents":
if (Array.isArray(whitelistedEvents)) {
return whitelistedEvents.find(
(eventObj) =>
eventObj.eventName.trim().toUpperCase() === formattedEventName
) === undefined
? true
: false;
} else {
return true;
return (
whitelistedEvents.find(
(eventObj) =>
eventObj.eventName.trim().toUpperCase() === formattedEventName
) === undefined
);
}
return true;

default:
return false;
}
Expand All @@ -747,7 +779,7 @@ class Analytics {

// assign page properties to context
// rudderElement.message.context.page = getDefaultPageProperties();

leaveBreadcrumb("Started sending data to destinations");
rudderElement.message.context.traits = {
...this.userTraits,
};
Expand Down Expand Up @@ -792,11 +824,12 @@ class Analytics {
);

// try to first send to all integrations, if list populated from BE
try {
succesfulLoadedIntersectClientSuppliedIntegrations.forEach((obj) => {

succesfulLoadedIntersectClientSuppliedIntegrations.forEach((obj) => {
try {
if (!obj.isFailed || !obj.isFailed()) {
if (obj[type]) {
let sendEvent = !this.IsEventBlackListed(
const sendEvent = !this.IsEventBlackListed(
rudderElement.message.event,
obj.name
);
Expand All @@ -808,10 +841,11 @@ class Analytics {
}
}
}
});
} catch (err) {
handleError({ message: `[sendToNative]:${err}` });
}
} catch (err) {
err.message = `[sendToNative]:: [Destination: ${obj.name}]:: "${err.message}"`;
handleError(err);
}
});

// config plane native enabled destinations, still not completely loaded
// in the page, add the events to a queue and process later
Expand Down Expand Up @@ -927,6 +961,8 @@ class Analytics {
* @memberof Analytics
*/
reset(flag) {
leaveBreadcrumb(`reset API :: flag: ${flag}`);

if (!this.loaded) return;
if (flag) {
this.anonymousId = "";
Expand Down Expand Up @@ -1012,11 +1048,9 @@ class Analytics {
this.cookieConsentOptions = cloneDeep(options.cookieConsentManager);
let configUrl = CONFIG_URL;
if (!this.isValidWriteKey(writeKey) || !this.isValidServerUrl(serverUrl)) {
handleError({
message:
"[Analytics] load:: Unable to load due to wrong writeKey or serverUrl",
});
throw Error("failed to initialize");
throw Error(
"Unable to load the SDK due to invalid writeKey or serverUrl"
);
}

let storageOptions = {};
Expand Down Expand Up @@ -1104,7 +1138,7 @@ class Analytics {
}
if (options && options.getSourceConfig) {
if (typeof options.getSourceConfig !== "function") {
handleError('option "getSourceConfig" must be a function');
handleError(new Error('option "getSourceConfig" must be a function'));
} else {
const res = options.getSourceConfig();

Expand Down
11 changes: 5 additions & 6 deletions buildspec.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ phases:
nodejs: 12
build:
commands:
- ls
- npm install --unsafe-perm
- npm run prodTest && npm test
- npm run buildProdBrowser
- sed 's|//# sourceMappingURL=rudder-analytics.min.js.map||' dist/rudder-analytics.min.js > dist/prod.js
- mv dist/prod.js dist/rudder-analytics.min.js
- aws s3 cp dist/rudder-analytics.min.js s3://$S3_BUCKET_NAME/rudder-analytics.min.js --cache-control max-age=3600 --acl public-read
- sed -i -e 's|{{RS_BUGSNAG_API_KEY}}|'$RS_BUGSNAG_API_KEY'|' dist/rudder-analytics.min.js
- aws s3 cp dist/rudder-analytics.min.js s3://$S3_BUCKET_NAME/v1/rudder-analytics.min.js --cache-control max-age=3600 --acl public-read
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/v1/rudder-analytics.min.js"
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/rudder-analytics.min.js"
- aws s3 cp dist/rudder-analytics.min.js.map s3://$S3_BUCKET_NAME/v1/rudder-analytics.min.js.map --cache-control max-age=3600 --acl public-read
- aws s3 cp s3://$S3_BUCKET_NAME/v1/rudder-analytics.min.js s3://$S3_BUCKET_NAME/rudder-analytics.min.js --cache-control max-age=3600 --acl public-read
- aws s3 cp s3://$S3_BUCKET_NAME/v1/rudder-analytics.min.js.map s3://$S3_BUCKET_NAME/rudder-analytics.min.js.map --cache-control max-age=3600 --acl public-read
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/v1/rudder-analytics.min.js" "/v1/rudder-analytics.min.js.map" "/rudder-analytics.min.js" "/rudder-analytics.min.js.map"
artifacts:
files:
- "**/*"
12 changes: 5 additions & 7 deletions buildspec.staging.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
version: 0.2


phases:
install:
runtime-versions:
nodejs: 12
build:
commands:
- ls
- npm install --unsafe-perm
- npm run prodTest && npm test
- npm run buildProdBrowser
- sed 's|//# sourceMappingURL=rudder-analytics.min.js.map||' dist/rudder-analytics.min.js > dist/prod.js
- mv dist/prod.js dist/rudder-analytics.min.js
- aws s3 cp dist/rudder-analytics.min.js s3://$S3_BUCKET_NAME/rudder-analytics-staging.min.js --cache-control max-age=3600 --acl public-read
- sed -i -e 's|rudder-analytics.min.js.map|rudder-analytics-staging.min.js.map|' -e 's|{{RS_BUGSNAG_API_KEY}}|'$RS_BUGSNAG_API_KEY'|' dist/rudder-analytics.min.js
- aws s3 cp dist/rudder-analytics.min.js s3://$S3_BUCKET_NAME/v1/rudder-analytics-staging.min.js --cache-control max-age=3600 --acl public-read
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/v1/rudder-analytics-staging.min.js"
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/rudder-analytics-staging.min.js"
- aws s3 cp dist/rudder-analytics.min.js.map s3://$S3_BUCKET_NAME/v1/rudder-analytics-staging.min.js.map --cache-control max-age=3600 --acl public-read
- aws s3 cp s3://$S3_BUCKET_NAME/v1/rudder-analytics-staging.min.js s3://$S3_BUCKET_NAME/rudder-analytics-staging.min.js --cache-control max-age=3600 --acl public-read
- aws s3 cp s3://$S3_BUCKET_NAME/v1/rudder-analytics-staging.min.js.map s3://$S3_BUCKET_NAME/rudder-analytics-staging.min.js.map --cache-control max-age=3600 --acl public-read
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/v1/rudder-analytics-staging.min.js" "/v1/rudder-analytics-staging.min.js.map" "/rudder-analytics-staging.min.js" "/rudder-analytics-staging.min.js.map"
artifacts:
files:
- "**/*"
2 changes: 2 additions & 0 deletions integrations/Amplitude/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint-disable class-methods-use-this */
import logger from "../../utils/logUtil";
import { type } from "../../utils/utils";
import { LOAD_ORIGIN } from "../ScriptLoader";
import { NAME } from "./constants";

class Amplitude {
Expand Down Expand Up @@ -63,6 +64,7 @@ class Amplitude {
"sha384-girahbTbYZ9tT03PWWj0mEVgyxtZoyDF9KVZdL+R53PP5wCY0PiVUKq0jeRlMx9M";
r.crossOrigin = "anonymous";
r.async = true;
r.dataset.loader = LOAD_ORIGIN;
r.src = "https://cdn.amplitude.com/libs/amplitude-7.2.1-min.gz.js";
r.onload = function () {
if (!e.amplitude.runQueuedFunctions) {
Expand Down
2 changes: 2 additions & 0 deletions integrations/BingAds/browser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logger from "../../utils/logUtil";
import { LOAD_ORIGIN } from "../ScriptLoader";
import { NAME } from "./constants";

class BingAds {
Expand All @@ -20,6 +21,7 @@ class BingAds {
(n = d.createElement(t)),
(n.src = r),
(n.async = 1),
(n.dataset.loader = LOAD_ORIGIN),
(n.onload = n.onreadystatechange =
function () {
let s = this.readyState;
Expand Down
2 changes: 2 additions & 0 deletions integrations/Braze/browser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable class-methods-use-this */
import logger from "../../utils/logUtil";
import { LOAD_ORIGIN } from "../ScriptLoader";
import { NAME } from "./constants";

/*
Expand Down Expand Up @@ -88,6 +89,7 @@ class Braze {
};
(y = p.createElement(P)).type = "text/javascript";
y.src = "https://js.appboycdn.com/web-sdk/2.4/appboy.min.js";
y.dataset.loader = LOAD_ORIGIN;
y.async = 1;
(b = p.getElementsByTagName(P)[0]).parentNode.insertBefore(y, b);
})(window, document, "script");
Expand Down
2 changes: 2 additions & 0 deletions integrations/Chartbeat/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
INTEGRATION_LOAD_CHECK_INTERVAL,
} from "../../utils/constants";
import { NAME } from "./constants";
import { LOAD_ORIGIN } from "../ScriptLoader";

class Chartbeat {
constructor(config, analytics) {
Expand Down Expand Up @@ -108,6 +109,7 @@ class Chartbeat {
e.type = "text/javascript";
e.async = true;
e.src = `//static.chartbeat.com/js/${script}`;
e.dataset.loader = LOAD_ORIGIN;
n.parentNode.insertBefore(e, n);
}
loadChartbeat();
Expand Down
Loading