samzilverberg/cordova-mixpanel-plugin

Support for append() and union() people methods

Closed this issue · 7 comments

Hello,

First of all, thanks for creating and maintaining such a great Cordova plugin!

Based on this guide (from Mixpanel docs) there're two methods that allows us to add elements to a property that is a list: union() and append() but I couldn't find those methods in this plugin.

Use mixpanel.people.union() [...], which will merge a value to a list or create that value if necessary, so what you end up with is a list that you can continue to build on [...]. Using a mixpanel.people.set call to set these sites as properties on Aaron’s people profile would cause previous sites to get overwritten each time Aaron worked at a new site, which is not the desired behavior.

// Objective-C (iOS)
// jane works at McDonalds
[mixpanel identify:@"jane"];

[mixpanel.people.union:@{
    @"organizations": @["McDonalds"],
    @"$name": @"jane"
}];
// Java (Android) 
// jane works at McDonalds
mixpanel.getPeople().identify("jane");
mixpanel.getPeople().union({
    "organizations": ["McDonalds"],
    "$name": "jane"
});

Are they currently being supported by this plugin?

hi @sebaferreras , i didn't implement union and append but after taking a short look in the android/ios related code they should be very simple to add (pretty much copy-paste all around with some light renaming:) ).
i'll try and add this this week, unless you wanna try it out yourself and open a PR.
let me know.

If you don't mind, please go ahead and add them when you have some time... I'll take a look at your implementation in order to learn for the next time (I know nothing about native iOS development).

Thanks again for your support :)

FYI i know very little about ios dev myself :)
I pretty much copy, paste, adapt, build try it out on ios simulator and fix whatevers not working 🤣

union and append added in 4.5.0
they both accept an object with key names and array values to union/append, example:

mixpanel.people.union({
  "organizations": ["McDonalds"],
  "$name": ["jane"]
})

NOTICE that passing in "$name": "jane" as per your comment will throw an error because "jane" is not inside an array.

Looks great, thanks @samzilverberg 👏

@samzilverberg why is this code deviating from the mixpanel-js api? I am able to construct union objects with strings as values without having to place them in arrays on the web version of mixpanel.

On further thought, it just seems to make no sense. $firstName should be a string, why would you want to place that value in an array anyway?