Skip to content

Commit

Permalink
add mixpanel alias call
Browse files Browse the repository at this point in the history
  • Loading branch information
arajguha committed Jul 25, 2021
1 parent 3f0e804 commit 5c52fde
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions integrations/Mixpanel/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ class Mixpanel {
* @param {*} rudderElement
*/
group(rudderElement) {
const { message } = rudderElement;
const { userId, groupId, traits } = message;
const { userId, groupId, traits } = rudderElement.message;
if (!userId) {
logger.debug("===Mixpanel: valid userId is required for group===");
return;
Expand All @@ -263,7 +262,7 @@ class Mixpanel {
logger.debug("===Mixpanel: valid groupId is required for group===");
return;
}
if (this.groupIdentifierTraits.length === 0) {
if (!this.groupIdentifierTraits || this.groupIdentifierTraits.length === 0) {
logger.debug("===Mixpanel: groupIdentifierTraits is required for group===");
return;
}
Expand All @@ -281,6 +280,27 @@ class Mixpanel {
identifierTraitsList.forEach(trait => window.mixpanel.set_group(trait, [groupId]));
}

/**
* @param {*} rudderElement
*/
alias(rudderElement) {
const { previousId, userId } = rudderElement.message;
if (!previousId) {
logger.debug("===Mixpanel: previousId is required for alias call===");
return;
}
if (!userId) {
logger.debug("===Mixpanel: userId is required for alias call===");
return;
}

if (window.mixpanel.get_distinct_id && window.mixpanel.get_distinct_id() === userId) {
logger.debug("===Mixpanel: userId is same as previousId. Skipping alias ===");
return;
}
window.mixpanel.alias(userId, previousId);
}

/**
* Since Mixpanel doesn't support lists of objects, invert each list of objects to a set of lists of object properties.
* Treats list transformation atomically, e.g. will only transform if EVERY item in list is an object
Expand Down

0 comments on commit 5c52fde

Please sign in to comment.