Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LaunchDarkly new integration #410

Merged
merged 6 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
69 changes: 69 additions & 0 deletions integrations/LaunchDarkly/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* eslint-disable class-methods-use-this */
import logger from "../../utils/logUtil";
import ScriptLoader from "../ScriptLoader";
import createUser from "./utils";

class LaunchDarkly {
constructor(config) {
this.name = "LaunchDarkly";
this.clientSideId = config.clientSideId;
}

init() {
logger.debug("===in init LaunchDarkly===");
if (!this.clientSideId) {
logger.error(
`${this.name} :: Unable to initialize destination - clientSideId is missing in config`
);
return;
}
ScriptLoader(null, "https://unpkg.com/launchdarkly-js-client-sdk@2");
}

isLoaded() {
logger.debug("===In isLoaded LaunchDarkly===");
return !!window.LDClient;
}

isReady() {
logger.debug("===In isReady LaunchDarkly===");
return this.isLoaded();
}

identify(rudderElement) {
const { message } = rudderElement;
window.user = createUser(message);

if (window.ldclient) {
window.ldclient.identify(window.user);
} else {
window.ldclient = window.LDClient.initialize(
this.clientSideId,
window.user
);
}
}

track(rudderElement) {
const { event, properties } = rudderElement.message;
if (window.ldclient) {
window.ldclient.track(event, properties);
} else
logger.error(
"=== In LaunchDarkly, track is not supported before identify ==="
);
}

alias(rudderElement) {
const { message } = rudderElement;
const newUser = { key: message.userId };

if (window.ldclient) {
window.ldclient.alias(newUser, window.user);
} else
logger.error(
"=== In LaunchDarkly, alias is not supported before identify ==="
);
}
}
export default LaunchDarkly;
3 changes: 3 additions & 0 deletions integrations/LaunchDarkly/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import LaunchDarkly from "./browser";

export default LaunchDarkly;
21 changes: 21 additions & 0 deletions integrations/LaunchDarkly/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const createUser = (message) => {
const user = {};
user.key = message.userId || message.anonymousId;
const { traits } = message.context;
if (traits.anonymous !== undefined) {
user.anonymous = traits.anonymous;
}
if (traits.avatar !== undefined) user.avatar = traits.avatar;
if (traits.country !== undefined) user.country = traits.country;
if (traits.custom !== undefined) user.custom = traits.custom;
if (traits.email !== undefined) user.email = traits.email;
if (traits.firstName !== undefined) user.firstName = traits.firstName;
if (traits.ip !== undefined) user.ip = traits.ip;
if (traits.lastName !== undefined) user.lastName = traits.lastName;
if (traits.name !== undefined) user.name = traits.name;
if (traits.privateAttributeNames !== undefined)
user.privateAttributeNames = traits.privateAttributeNames;
if (traits.secondary !== undefined) user.secondary = traits.secondary;
return user;
};
export default createUser;
1 change: 1 addition & 0 deletions integrations/client_server_name.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const clientToServerNames = {
SENTRY: "Sentry",
GOOGLE_OPTIMIZE: "GoogleOptimize",
POST_AFFILIATE_PRO: "PostAffiliatePro",
LAUNCHDARKLY:"LaunchDarkly"
};

export { clientToServerNames };
2 changes: 2 additions & 0 deletions integrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import * as TVSquared from "./TVSquared";
import * as VWO from "./VWO";
import * as GoogleOptimize from "./GoogleOptimize";
import * as PostAffiliatePro from "./PostAffiliatePro";
import * as LaunchDarkly from "./LaunchDarkly";

// 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 @@ -91,6 +92,7 @@ const integrations = {
VWO: VWO.default,
GOOGLE_OPTIMIZE: GoogleOptimize.default,
POST_AFFILIATE_PRO: PostAffiliatePro.default,
LAUNCHDARKLY: LaunchDarkly.default
};

export { integrations };
5 changes: 5 additions & 0 deletions integrations/integration_cname.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ const commonNames = {
postaffiliatepro: "POST_AFFILIATE_PRO",
POSTAFFILIATEPRO: "POST_AFFILIATE_PRO",
POST_AFFILIATE_PRO: "POST_AFFILIATE_PRO",
LaunchDarkly:"LAUNCHDARKLY",
Launch_Darkly:"LAUNCHDARKLY",
LAUNCHDARKLY:"LAUNCHDARKLY",
"Launch Darkly":"LAUNCHDARKLY",
launchDarkly:"LAUNCHDARKLY"
};

export { commonNames };