Skip to content

Commit

Permalink
chore: resolved tech debt for june, keen, kissmetrics, klaviyo and le…
Browse files Browse the repository at this point in the history
…mnisk
  • Loading branch information
mihir-4116 committed Oct 9, 2023
1 parent 2d4c196 commit 99c6e63
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 48 deletions.
26 changes: 15 additions & 11 deletions packages/analytics-js-integrations/src/integrations/June/browser.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
/* eslint-disable class-methods-use-this */
/* eslint-disable no-underscore-dangle */
import get from 'get-value';
import { logger } from '@rudderstack/analytics-js-common/v1.1/utils/logUtil';
import { NAME } from '@rudderstack/analytics-js-common/constants/integrations/June/constants';
import {
NAME,
DISPLAY_NAME,
} from '@rudderstack/analytics-js-common/constants/integrations/June/constants';
import { ScriptLoader } from '@rudderstack/analytics-js-common/v1.1/utils/ScriptLoader';
import Logger from '../../utils/logger';
import { getDestinationExternalID } from '../../utils/commonUtils';

const logger = new Logger(NAME);

class June {
constructor(config, analytics, destinationInfo) {
if (analytics.logLevel) {
Expand All @@ -31,43 +36,42 @@ class June {
}

init() {
logger.debug('===In init June===');
this.loadScript();
}

isLoaded() {
logger.debug('===In isLoaded June===');
logger.debug(`In isLoaded ${DISPLAY_NAME}`);
return !!window.analytics && typeof window.analytics === 'object';
}

isReady() {
logger.debug('===In isReady June===');
logger.debug(`In isReady ${DISPLAY_NAME}`);
return !!window.analytics && typeof window.analytics === 'object';
}

page(rudderElement) {
logger.debug('===In June page===');
logger.debug(`In ${DISPLAY_NAME} page`);
const { name, properties } = rudderElement.message;
window.analytics.page(name, properties);
}

identify(rudderElement) {
logger.debug('===In June identify===');
logger.debug(`In ${DISPLAY_NAME} identify`);
const { message } = rudderElement;
const userId =
get(message, 'userId') ||
get(message, 'context.traits.userId') ||
get(message, 'context.traits.Id');
if (!userId) {
logger.error('userId is required for an identify call');
logger.error(`${DISPLAY_NAME} : userId is required for an identify call`);
return;
}
const traits = get(message, 'context.traits');
window.analytics.identify(userId, traits);
}

track(rudderElement) {
logger.debug('===In June track===');
logger.debug(`In ${DISPLAY_NAME} track`);
let groupId;
const { message } = rudderElement;
const externalGroupId = getDestinationExternalID(message, 'juneGroupId');
Expand All @@ -84,10 +88,10 @@ class June {
}

group(rudderElement) {
logger.debug('===In June group===');
logger.debug(`In ${DISPLAY_NAME} group`);
const { groupId } = rudderElement.message;
if (!groupId) {
logger.error('groupId is required for group call');
logger.error(`${DISPLAY_NAME} : groupId is required for group call`);
return;
}
const { traits } = rudderElement.message;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { logger } from '@rudderstack/analytics-js-common/v1.1/utils/logUtil';
import { ScriptLoader } from '@rudderstack/analytics-js-common/v1.1/utils/ScriptLoader';
import { NAME } from '@rudderstack/analytics-js-common/constants/integrations/Keen/constants';
/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable no-template-curly-in-string */
/* eslint-disable no-use-before-define */
import { ScriptLoader } from '@rudderstack/analytics-js-common/v1.1/utils/ScriptLoader';
import {
NAME,
DISPLAY_NAME,
} from '@rudderstack/analytics-js-common/constants/integrations/Keen/constants';
import Logger from '../../utils/logger';

const logger = new Logger(NAME);

class Keen {
constructor(config, analytics, destinationInfo) {
Expand All @@ -26,7 +31,6 @@ class Keen {
}

init() {
logger.debug('===in init Keen===');
ScriptLoader('keen-integration', 'https://cdn.jsdelivr.net/npm/keen-tracking@4');

const check = setInterval(checkAndInitKeen.bind(this), 1000);
Expand All @@ -46,16 +50,17 @@ class Keen {
}

isLoaded() {
logger.debug('in Keen isLoaded');
logger.debug(`In isLoaded ${DISPLAY_NAME}`);
return !!(this.client != null);
}

isReady() {
logger.debug(`In isReady ${DISPLAY_NAME}`);
return !!(this.client != null);
}

identify(rudderElement) {
logger.debug('in Keen identify');
logger.debug(`In ${DISPLAY_NAME} identify`);

const { message } = rudderElement;
let { userId } = message;
Expand All @@ -73,7 +78,7 @@ class Keen {
}

track(rudderElement) {
logger.debug('in Keen track');
logger.debug(`In ${DISPLAY_NAME} track`);

const { event } = rudderElement.message;
let { properties } = rudderElement.message;
Expand All @@ -82,7 +87,7 @@ class Keen {
}

page(rudderElement) {
logger.debug('in Keen page');
logger.debug(`In ${DISPLAY_NAME} page`);

let { properties } = rudderElement.message;
const pageName = rudderElement.message.name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
import is from 'is';
import extend from '@ndhoule/extend';
import each from 'component-each';
import { logger } from '@rudderstack/analytics-js-common/v1.1/utils/logUtil';
import { NAME } from '@rudderstack/analytics-js-common/constants/integrations/Kissmetrics/constants';
import {
NAME,
DISPLAY_NAME,
} from '@rudderstack/analytics-js-common/constants/integrations/Kissmetrics/constants';
import Logger from '../../utils/logger';
import { getRevenue } from '../../utils/utils';
import { loadeNativeSdk } from './nativeSdkLoader';

const logger = new Logger(NAME);

class Kissmetrics {
constructor(config, analytics, destinationInfo) {
if (analytics.logLevel) {
Expand All @@ -25,7 +30,6 @@ class Kissmetrics {
}

init() {
logger.debug('===in init Kissmetrics===');
loadeNativeSdk(this.apiKey);

if (this.isEnvMobile()) {
Expand All @@ -34,10 +38,12 @@ class Kissmetrics {
}

isLoaded() {
logger.debug(`In isLoaded ${DISPLAY_NAME}`);
return is.object(window.KM);
}

isReady() {
logger.debug(`In isReady ${DISPLAY_NAME}`);
return is.object(window.KM);
}

Expand Down Expand Up @@ -157,7 +163,7 @@ class Kissmetrics {
}

identify(rudderElement) {
logger.debug('in KissMetrics identify');
logger.debug(`In ${DISPLAY_NAME} identify`);

const { userId, context } = rudderElement.message;
const { traits } = context;
Expand All @@ -172,7 +178,7 @@ class Kissmetrics {
}

track(rudderElement) {
logger.debug('in KissMetrics track');
logger.debug(`In ${DISPLAY_NAME} track`);

const { event } = rudderElement.message;
let properties = JSON.parse(JSON.stringify(rudderElement.message.properties));
Expand Down Expand Up @@ -212,7 +218,7 @@ class Kissmetrics {
}

page(rudderElement) {
logger.debug('in KissMetrics page');
logger.debug(`In ${DISPLAY_NAME} page`);

let { properties } = rudderElement.message;
const pageName = rudderElement.message.name;
Expand All @@ -233,14 +239,13 @@ class Kissmetrics {
}

alias(rudderElement) {
logger.debug('in KissMetrics alias');

logger.debug(`In ${DISPLAY_NAME} alias`);
const { previousId, userId } = rudderElement.message;
window._kmq.push(['alias', userId, previousId]);
}

group(rudderElement) {
logger.debug('in KissMetrics group');
logger.debug(`In ${DISPLAY_NAME} group`);

const { groupId, traits } = rudderElement.message;
const groupTraits = this.prefix('Group', traits);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
/* eslint-disable class-methods-use-this */
/* eslint-disable no-underscore-dangle */
import get from 'get-value';
import { logger } from '@rudderstack/analytics-js-common/v1.1/utils/logUtil';
import { ScriptLoader } from '@rudderstack/analytics-js-common/v1.1/utils/ScriptLoader';
import { NAME } from '@rudderstack/analytics-js-common/constants/integrations/Klaviyo/constants';
import {
NAME,
DISPLAY_NAME,
} from '@rudderstack/analytics-js-common/constants/integrations/Klaviyo/constants';
import Logger from '../../utils/logger';
import { extractCustomFields, getDefinedTraits } from '../../utils/utils';
import ecommEventPayload from './util';
import { isNotEmpty } from '../../utils/commonUtils';

const logger = new Logger(NAME);

class Klaviyo {
constructor(config, analytics, destinationInfo) {
if (analytics.logLevel) {
Expand Down Expand Up @@ -81,29 +86,26 @@ class Klaviyo {
}

init() {
logger.debug('===in init Klaviyo===');
ScriptLoader(
'klaviyo-integration',
`https://static.klaviyo.com/onsite/js/klaviyo.js?company_id=${this.publicApiKey}`,
);
}

isLoaded() {
logger.debug('===in isLoaded Klaviyo===');

logger.debug(`In isLoaded ${DISPLAY_NAME}`);
return !!(window._learnq && window._learnq.push !== Array.prototype.push);
}

isReady() {
logger.debug('===in isReady Klaviyo===');

logger.debug(`In isReady ${DISPLAY_NAME}`);
return !!(window._learnq && window._learnq.push !== Array.prototype.push);
}

identify(rudderElement) {
const { message } = rudderElement;
if (!(message.context && message.context.traits)) {
logger.error('user traits not present');
logger.error(`${DISPLAY_NAME} : user traits not present`);
return;
}

Expand All @@ -123,7 +125,7 @@ class Klaviyo {
$zip: get(message, 'context.traits.zip'),
};
if (!payload.$email && !payload.$phone_number && !payload.$id) {
logger.error('user id, phone or email not present');
logger.error(`${DISPLAY_NAME} : user id, phone or email not present`);
return;
}
if (this.enforceEmailAsPrimary) {
Expand All @@ -134,7 +136,7 @@ class Klaviyo {
try {
payload = extractCustomFields(message, payload, this.keysToExtract, this.exclusionKeys);
} catch (err) {
logger.debug(`Error occured at extractCustomFields ${err}`);
logger.debug(`${DISPLAY_NAME} : Error occured at extractCustomFields ${err}`);
}
window._learnq.push(['identify', payload]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* eslint-disable class-methods-use-this */
import { NAME } from '@rudderstack/analytics-js-common/constants/integrations/Lemnisk/constants';
import {
NAME,
DISPLAY_NAME,
} from '@rudderstack/analytics-js-common/constants/integrations/Lemnisk/constants';
import Logger from '../../utils/logger';
import { loadNativeSdk } from './nativeSdkLoader';

Expand All @@ -21,26 +24,25 @@ class Lemnisk {
}

init() {
logger.debug('===in init Lemnisk Marketing Automation===');
loadNativeSdk(this.accountId, this.sdkWriteKey);
}

isLoaded() {
logger.debug('===In isLoaded Lemnisk Marketing Automation===');
logger.debug(`In isLoaded ${DISPLAY_NAME}`);
return !!window.lmSMTObj;
}

isReady() {
logger.debug('===In isReady Lemnisk Marketing Automation===');
logger.debug(`In isReady ${DISPLAY_NAME}`);
return !!window.lmSMTObj;
}

identify(rudderElement) {
logger.debug('===In Lemnisk Marketing Automation identify===');
logger.debug(`In ${DISPLAY_NAME} identify`);

const userId = rudderElement.message.userId || rudderElement.message.anonymousId;
if (!userId) {
logger.debug('[Lemnisk] identify:: user id is required');
logger.debug(`${DISPLAY_NAME} : user id is required`);
return;
}
const { message } = rudderElement;
Expand All @@ -51,11 +53,11 @@ class Lemnisk {
}

track(rudderElement) {
logger.debug('===In Lemnisk Marketing Automation track===');
logger.debug(`In ${DISPLAY_NAME} track`);
const { event, properties } = rudderElement.message;

if (!event) {
logger.error('[Lemnisk] track:: Event name is missing!');
logger.error(`${DISPLAY_NAME} : Event name is missing`);
return;
}
if (properties) {
Expand All @@ -67,7 +69,8 @@ class Lemnisk {
}

page(rudderElement) {
logger.debug('===In Lemnisk Marketing Automation page===');
logger.debug(`In ${DISPLAY_NAME} page`);

const { name, properties } = rudderElement.message;
if (name && !properties) {
window.lmSMTObj.page(name, { isRudderEvents: true });
Expand Down

0 comments on commit 99c6e63

Please sign in to comment.