Skip to content

Commit

Permalink
feat(new integration): onboarding june device mode destination (#663)
Browse files Browse the repository at this point in the history
* feat(new integration): onboarding june device mode destination

* feat(new integration): externalId support in track call

* feat(new integration): review comments addressed

Co-authored-by: shrouti1507 <[email protected]>
  • Loading branch information
Gauravudia and shrouti1507 authored Sep 28, 2022
1 parent abed89b commit 9a6c64c
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 4 deletions.
90 changes: 90 additions & 0 deletions integrations/June/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* eslint-disable class-methods-use-this */
/* eslint-disable no-underscore-dangle */
/* eslint-disable prettier/prettier */
import get from "get-value";
import logger from "../../utils/logUtil";
import { NAME } from "./constants";
import ScriptLoader from "../ScriptLoader";
import { getDestinationExternalID } from "../utils/commonUtils";

class June {
constructor(config) {
this.name = NAME;
this.apiKey = config.apiKey;
}

loadScript() {
window.analytics = {};
ScriptLoader(
"june-integration",
"https://unpkg.com/@june-so/analytics-next/dist/umd/standalone.js"
);
window.analytics._writeKey = this.apiKey;
}

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

isLoaded() {
logger.debug("===In isLoaded June===");
return !!window.analytics && typeof window.analytics === "object";
}

isReady() {
logger.debug("===In isReady June===");
return !!window.analytics && typeof window.analytics === "object";
}

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

identify(rudderElement) {
logger.debug("===In June 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");
return;
}
const traits = get(message, "context.traits");
window.analytics.identify(userId, traits);
}

track(rudderElement) {
logger.debug("===In June track===");
let groupId;
const { message } = rudderElement;
const externalGroupId = getDestinationExternalID(message, "juneGroupId");
const { event } = message;
let { properties } = message;
({ groupId, ...properties } = properties || {});
groupId = externalGroupId || groupId;

if (groupId) {
window.analytics.track(event, properties, { groupId });
} else {
window.analytics.track(event, properties);
}
}

group(rudderElement) {
logger.debug("===In June group===");
const { groupId } = rudderElement.message;
if (!groupId) {
logger.error("groupId is required for group call");
return;
}
const { traits } = rudderElement.message;
window.analytics.group(groupId, traits);
}
}

export default June;
8 changes: 8 additions & 0 deletions integrations/June/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const NAME = "JUNE";
const CNameMapping = {
[NAME]: NAME,
June: NAME,
june: NAME,
};

export { NAME, CNameMapping };
3 changes: 3 additions & 0 deletions integrations/June/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import June from "./browser";

export default June;
1 change: 1 addition & 0 deletions integrations/client_server_name.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const clientToServerNames = {
WOOPRA: "Woopra",
ROLLBAR: "RollBar",
QUORA_PIXEL: "Quora Pixel",
JUNE: "June",
};

export { clientToServerNames };
4 changes: 2 additions & 2 deletions integrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import * as Shynet from "./Shynet";
import * as Woopra from "./Woopra";
import * as RollBar from "./RollBar";
import * as QuoraPixel from "./QuoraPixel";

import * as June from "./June";

// the key names should match the destination.name value to keep partity everywhere
// (config-plan name, native destination.name , exported integration name(this one below))
Expand Down Expand Up @@ -122,7 +122,7 @@ const integrations = {
WOOPRA: Woopra.default,
ROLLBAR: RollBar.default,
QUORA_PIXEL: QuoraPixel.default,

JUNE: June.default,
};

export { integrations };
4 changes: 2 additions & 2 deletions integrations/integration_cname.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import { CNameMapping as Shynet } from "./Shynet/constants";
import { CNameMapping as Woopra } from "./Woopra/constants";
import { CNameMapping as RollBar } from "./RollBar/constants";
import { CNameMapping as QuoraPixel } from "./QuoraPixel/constants";

import { CNameMapping as June } from "./June/constants";

// for sdk side native integration identification
// add a mapping from common names to index.js exported key names as identified by Rudder
Expand Down Expand Up @@ -122,7 +122,7 @@ const commonNames = {
...Woopra,
...RollBar,
...QuoraPixel,

...June,
};

export { commonNames };
29 changes: 29 additions & 0 deletions integrations/utils/commonUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,39 @@ function getEventMappingFromConfig(event, eventsHashmap) {
return null;
}

// External ID format
// {
// "context": {
// "externalId": [
// {
// "type": "kustomerId",
// "id": "12345678"
// }
// ]
// }
// }
// to get destination specific external id passed in context.
function getDestinationExternalID(message, type) {
let externalIdArray = null;
let destinationExternalId = null;
if (message.context && message.context.externalId) {
externalIdArray = message.context.externalId;
}
if (externalIdArray) {
externalIdArray.forEach((extIdObj) => {
if (extIdObj.type === type) {
destinationExternalId = extIdObj.id;
}
});
}
return destinationExternalId;
}

export {
getEventMappingFromConfig,
getHashFromArrayWithDuplicate,
getHashFromArray,
getDestinationExternalID,
toIso,
flattenJson,
removeUndefinedValues,
Expand Down

0 comments on commit 9a6c64c

Please sign in to comment.