Skip to content

Commit 2d4c196

Browse files
committed
chore: resolved tech debt for hotjar, hubspot, intercom, iterable and launch darkly
1 parent 75618f4 commit 2d4c196

File tree

5 files changed

+66
-45
lines changed

5 files changed

+66
-45
lines changed

packages/analytics-js-integrations/src/integrations/Hotjar/browser.js

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
/* eslint-disable no-underscore-dangle */
22
/* eslint-disable class-methods-use-this */
3-
import { logger } from '@rudderstack/analytics-js-common/v1.1/utils/logUtil';
4-
import { NAME } from '@rudderstack/analytics-js-common/constants/integrations/Hotjar/constants';
3+
import {
4+
NAME,
5+
DISPLAY_NAME,
6+
} from '@rudderstack/analytics-js-common/constants/integrations/Hotjar/constants';
7+
import Logger from '../../utils/logger';
58
import { loadNativeSdk } from './nativeSdkLoader';
69

10+
const logger = new Logger(NAME);
11+
712
class Hotjar {
813
constructor(config, analytics, destinationInfo) {
914
if (analytics.logLevel) {
@@ -21,27 +26,26 @@ class Hotjar {
2126
}
2227

2328
init() {
24-
logger.debug('===In init Hotjar===');
2529
loadNativeSdk(this.siteId);
2630
this._ready = true;
2731
}
2832

2933
isLoaded() {
30-
logger.debug('===In isLoaded Hotjar===');
34+
logger.debug(`In isLoaded ${DISPLAY_NAME}`);
3135
return this._ready;
3236
}
3337

3438
isReady() {
35-
logger.debug('===In isReady Hotjar===');
39+
logger.debug(`In isReady ${DISPLAY_NAME}`);
3640
return this._ready;
3741
}
3842

3943
identify(rudderElement) {
40-
logger.debug('===In Hotjar identify===');
44+
logger.debug(`In ${DISPLAY_NAME} identify`);
4145

4246
const userId = rudderElement.message.userId || rudderElement.message.anonymousId;
4347
if (!userId) {
44-
logger.debug('[Hotjar] identify:: user id is required');
48+
logger.debug(`${DISPLAY_NAME} : user id is required for an identify call`);
4549
return;
4650
}
4751

@@ -51,17 +55,17 @@ class Hotjar {
5155
}
5256

5357
track(rudderElement) {
54-
logger.debug('===In Hotjar track===');
58+
logger.debug(`In ${DISPLAY_NAME} track`);
5559

5660
let { event } = rudderElement.message;
5761

5862
if (!event) {
59-
logger.error('Event name is not present');
63+
logger.error(`${DISPLAY_NAME} : Event name is not present`);
6064
return;
6165
}
6266

6367
if (typeof event !== 'string') {
64-
logger.error('Event name should be string');
68+
logger.error(`${DISPLAY_NAME} : Event name should be string`);
6569
return;
6670
}
6771

@@ -76,11 +80,6 @@ class Hotjar {
7680
window.hj('event', event);
7781
}
7882
}
79-
80-
page() {
81-
logger.debug('===In Hotjar page===');
82-
logger.debug('[Hotjar] page:: method not supported');
83-
}
8483
}
8584

8685
export { Hotjar };

packages/analytics-js-integrations/src/integrations/HubSpot/browser.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
/* eslint-disable no-underscore-dangle */
22
/* eslint-disable class-methods-use-this */
33
import { ScriptLoader } from '@rudderstack/analytics-js-common/v1.1/utils/ScriptLoader';
4-
import { logger } from '@rudderstack/analytics-js-common/v1.1/utils/logUtil';
5-
import { NAME } from '@rudderstack/analytics-js-common/constants/integrations/HubSpot/constants';
4+
import {
5+
NAME,
6+
DISPLAY_NAME,
7+
} from '@rudderstack/analytics-js-common/constants/integrations/HubSpot/constants';
8+
import Logger from '../../utils/logger';
69
import { getDefinedTraits } from '../../utils/utils';
710

11+
const logger = new Logger(NAME);
12+
813
class HubSpot {
914
constructor(config, analytics, destinationInfo) {
1015
if (analytics.logLevel) {
@@ -23,28 +28,28 @@ class HubSpot {
2328
init() {
2429
const hubSpotJs = `https://js.hs-scripts.com/${this.hubId}.js`;
2530
ScriptLoader('hubspot-integration', hubSpotJs);
26-
logger.debug('===in init HS===');
2731
}
2832

2933
isLoaded() {
30-
logger.debug('in HubSpotAnalyticsManager isLoaded');
34+
logger.debug(`In isLoaded ${DISPLAY_NAME}`);
3135
return !!(window._hsq && window._hsq.push !== Array.prototype.push);
3236
}
3337

3438
isReady() {
39+
logger.debug(`In isReady ${DISPLAY_NAME}`);
3540
return !!(window._hsq && window._hsq.push !== Array.prototype.push);
3641
}
3742

3843
identify(rudderElement) {
39-
logger.debug('in HubSpotAnalyticsManager identify');
44+
logger.debug(`In ${DISPLAY_NAME} identify`);
4045

4146
const { message } = rudderElement;
4247
const { traits } = message.context;
4348

4449
const { userId, email } = getDefinedTraits(message);
4550

4651
if (!email) {
47-
logger.error('Email is required');
52+
logger.error(`${DISPLAY_NAME} : Email is required`);
4853
return;
4954
}
5055

@@ -70,7 +75,7 @@ class HubSpot {
7075
}
7176

7277
track(rudderElement) {
73-
logger.debug('in HubSpotAnalyticsManager track');
78+
logger.debug(`In ${DISPLAY_NAME} track`);
7479

7580
const { properties, event } = rudderElement.message;
7681
const eventValue = {
@@ -82,7 +87,7 @@ class HubSpot {
8287
}
8388

8489
page(rudderElement) {
85-
logger.debug('in HubSpotAnalyticsManager page');
90+
logger.debug(`In ${DISPLAY_NAME} page`);
8691

8792
const { properties } = rudderElement.message;
8893
const { path } = properties;

packages/analytics-js-integrations/src/integrations/INTERCOM/browser.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
/* eslint-disable class-methods-use-this */
2-
import { logger } from '@rudderstack/analytics-js-common/v1.1/utils/logUtil';
3-
import { NAME } from '@rudderstack/analytics-js-common/constants/integrations/INTERCOM/constants';
2+
import {
3+
NAME,
4+
DISPLAY_NAME,
5+
} from '@rudderstack/analytics-js-common/constants/integrations/INTERCOM/constants';
6+
import Logger from '../../utils/logger';
47
import { loadNativeSdk } from './nativeSdkLoader';
58
import { flattenJsonPayload } from '../../utils/utils';
69
import { processNameField, processCompanyField, processIdentityVerificationProps } from './utils';
710

11+
const logger = new Logger(NAME);
12+
813
class INTERCOM {
914
constructor(config, analytics, destinationInfo) {
1015
if (analytics.logLevel) {
@@ -25,10 +30,12 @@ class INTERCOM {
2530
}
2631

2732
isLoaded() {
33+
logger.debug(`In isLoaded ${DISPLAY_NAME}`);
2834
return !!window.intercom_code;
2935
}
3036

3137
isReady() {
38+
logger.debug(`In isReady ${DISPLAY_NAME}`);
3239
return !!window.intercom_code;
3340
}
3441

packages/analytics-js-integrations/src/integrations/Iterable/browser.js

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/* eslint-disable class-methods-use-this */
22
import get from 'get-value';
33
import { ScriptLoader } from '@rudderstack/analytics-js-common/v1.1/utils/ScriptLoader';
4-
import { NAME } from '@rudderstack/analytics-js-common/constants/integrations/Iterable/constants';
4+
import {
5+
NAME,
6+
DISPLAY_NAME,
7+
} from '@rudderstack/analytics-js-common/constants/integrations/Iterable/constants';
58
import Logger from '../../utils/logger';
69
import {
710
formPurchaseEventPayload,
@@ -53,22 +56,21 @@ class Iterable {
5356
}
5457

5558
init() {
56-
logger.debug('===In init Iterable===');
5759
ScriptLoader('iterable-web', 'https://unpkg.com/@iterable/web-sdk/index.js');
5860
}
5961

6062
isLoaded() {
61-
logger.debug('===In isLoaded Iterable===');
63+
logger.debug(`In isLoaded ${DISPLAY_NAME}`);
6264
return !!window[iterableWebSdk];
6365
}
6466

6567
isReady() {
66-
logger.debug('===In isReady Iterable===');
68+
logger.debug(`In isReady ${DISPLAY_NAME}`);
6769
return !!window[iterableWebSdk];
6870
}
6971

7072
identify(rudderElement) {
71-
logger.debug('===In identify Iterable');
73+
logger.debug(`In ${DISPLAY_NAME} identify`);
7274

7375
const { message } = rudderElement;
7476
const { integrations, traits, context, userId } = message;
@@ -77,7 +79,9 @@ class Iterable {
7779
const jwtToken = extractJWT(integrations);
7880

7981
if (!jwtToken) {
80-
logger.error('The JWT token was not passed, The SDK could not be initialised');
82+
logger.error(
83+
`${DISPLAY_NAME} : The JWT token was not passed, The SDK could not be initialized`,
84+
);
8185
return;
8286
}
8387

@@ -86,11 +90,11 @@ class Iterable {
8690

8791
if (this.initialisationIdentifier === 'userId') {
8892
wd.setUserID(userId).then(() => {
89-
logger.debug('userId set');
93+
logger.debug(`${DISPLAY_NAME} : userId set`);
9094
});
9195
} else {
9296
wd.setEmail(userEmail).then(() => {
93-
logger.debug('userEmail set');
97+
logger.debug(`${DISPLAY_NAME} : userEmail set`);
9498
});
9599
}
96100
/* Available pop-up push notification settings configurable from UI
@@ -123,15 +127,15 @@ class Iterable {
123127
}
124128

125129
track(rudderElement) {
126-
logger.debug('===In track Iterable===');
130+
logger.debug(`In ${DISPLAY_NAME} track`);
127131

128132
const { message } = rudderElement;
129133
const { event, properties } = message;
130134
const eventPayload = removeUndefinedAndNullValues(properties);
131135
const userEmail = get(message, 'context.traits.email');
132136
const userId = get(message, 'userId');
133137
if (!event) {
134-
logger.error('Event name not present');
138+
logger.error(`${DISPLAY_NAME} : Event name not present`);
135139
return;
136140
}
137141
if (
@@ -148,7 +152,7 @@ class Iterable {
148152
eventName: 'Track getInAppMessages',
149153
dataFields: eventPayload,
150154
})
151-
.then(logger.debug('Web in-app push triggered'));
155+
.then(logger.debug(`${DISPLAY_NAME} : Web in-app push triggered`));
152156
}
153157
} else if (
154158
isNotEmpty(this.purchaseEventMapping) &&
@@ -173,10 +177,12 @@ class Iterable {
173177
*/
174178
// Either email or userId must be passed in to identify the user.
175179
// If both are passed in, email takes precedence.
176-
logger.debug(`The event ${event} is not mapped in the dashboard, firing a custom event`);
180+
logger.debug(
181+
`${DISPLAY_NAME} : The event ${event} is not mapped in the dashboard, firing a custom event`,
182+
);
177183
window[iterableWebSdk]
178184
.track({ email: userEmail, userId, eventName: event, dataFields: eventPayload })
179-
.then(logger.debug('Track a custom event.'));
185+
.then(logger.debug(`${DISPLAY_NAME} : Track a custom event`));
180186
}
181187
}
182188
}

packages/analytics-js-integrations/src/integrations/LaunchDarkly/browser.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
/* eslint-disable class-methods-use-this */
2-
import { logger } from '@rudderstack/analytics-js-common/v1.1/utils/logUtil';
32
import { ScriptLoader } from '@rudderstack/analytics-js-common/v1.1/utils/ScriptLoader';
4-
import { NAME } from '@rudderstack/analytics-js-common/constants/integrations/LaunchDarkly/constants';
3+
import {
4+
NAME,
5+
DISPLAY_NAME,
6+
} from '@rudderstack/analytics-js-common/constants/integrations/LaunchDarkly/constants';
7+
import Logger from '../../utils/logger';
58
import { createUser, getDestinationOptions } from './utils';
69

10+
const logger = new Logger(NAME);
11+
712
class LaunchDarkly {
813
constructor(config, analytics, destinationInfo) {
914
if (analytics.logLevel) {
@@ -21,7 +26,6 @@ class LaunchDarkly {
2126
}
2227

2328
init() {
24-
logger.debug('===in init LaunchDarkly===');
2529
if (!this.clientSideId) {
2630
logger.error(
2731
`${this.name} :: Unable to initialize destination - clientSideId is missing in config`,
@@ -32,12 +36,12 @@ class LaunchDarkly {
3236
}
3337

3438
isLoaded() {
35-
logger.debug('===In isLoaded LaunchDarkly===');
39+
logger.debug(`In isLoaded ${DISPLAY_NAME}`);
3640
return !!window.LDClient;
3741
}
3842

3943
isReady() {
40-
logger.debug('===In isReady LaunchDarkly===');
44+
logger.debug(`In isReady ${DISPLAY_NAME}`);
4145
return this.isLoaded();
4246
}
4347

@@ -58,7 +62,7 @@ class LaunchDarkly {
5862
const { event, properties } = rudderElement.message;
5963
if (window.ldclient) {
6064
window.ldclient.track(event, properties);
61-
} else logger.error('=== In LaunchDarkly, track is not supported before identify ===');
65+
} else logger.error(`${DISPLAY_NAME} : track is not supported before identify`);
6266
}
6367

6468
alias(rudderElement) {
@@ -67,7 +71,7 @@ class LaunchDarkly {
6771

6872
if (window.ldclient) {
6973
window.ldclient.alias(newUser, this.launchDarklyUser);
70-
} else logger.error('=== In LaunchDarkly, alias is not supported before identify ===');
74+
} else logger.error(`${DISPLAY_NAME} : alias is not supported before identify`);
7175
}
7276
}
7377
export default LaunchDarkly;

0 commit comments

Comments
 (0)