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

Identify #13

Closed
bwship opened this issue Dec 14, 2012 · 17 comments

Comments

@bwship
Copy link

commented Dec 14, 2012

Hi,

Is there any plan to integrate mixpanel.identify

https://mixpanel.com/docs/getting-started/learn-the-basics

I am trying to track an event related to another user, so I want to identify them in my code with something like this

mixpanel.track 'ReferralClicked'
  objectId: req.body.objectId

Thanks,
Bob

@carlsverre

This comment has been minimized.

Copy link
Contributor

commented Dec 14, 2012

This library is a server side library so id doesn't have state (that would let you identify the library so it operates on a single user). To achieve what you want all you have to do is pass a distinct_id as the option to track like so:

mixpanel.track("ReferralClicked", {
    distinct_id: "some unique client id",
    other_property: "value"
});

@carlsverre carlsverre closed this Dec 14, 2012

@bwship

This comment has been minimized.

Copy link
Author

commented Dec 14, 2012

The way I am using it though is that I have a user that gets a referral link. If they send that to someone, and another user goes to the page with that referral code, then I want to do the tracking for the original user. So, from client-side, I track user 2 by identifying them, and then tracking that they went to the site. I then call this node code on the server, with the objectId of the original user, and want to identify them and then track the ReferralClicked event. This will basically give credit to user 1 that they referred someone. I am doing the disntict_id thing (objectid) in my case, but would also like the tracking to get identified to my user 1 in the mixpanel system.

@carlsverre

This comment has been minimized.

Copy link
Contributor

commented Dec 14, 2012

So if I understand you correctly, you want the "ReferralClicked" event to be tied to user 1. In that case just set distinct_id: "user_1_objectid" for the track call above. I don't see why you need identify.

@bwship

This comment has been minimized.

Copy link
Author

commented Dec 14, 2012

Within mixpanel, if you go into the Streams tab on the left for any active project you have, and then click the Stream tab at the top, and then events underneath you will see a live feed, that tracks events to the identified user, you can see this on the image in the link below

https://www.evernote.com/shard/s54/sh/88a46332-b195-4bae-8844-f614671d3b47/10aa4e3c5023f0a06df05085f75ff559

If I simply set the objectId in the track event, this tracking item never gets assigned to that user.

@carlsverre

This comment has been minimized.

Copy link
Contributor

commented Dec 14, 2012

Why are you setting objectId and not distinct_id?

@carlsverre

This comment has been minimized.

Copy link
Contributor

commented Dec 14, 2012

Also, you might want to make sure you set the name_tag property as well to be the name of user 1.

@bwship

This comment has been minimized.

Copy link
Author

commented Dec 14, 2012

Oh, does setting distinct_id for tracking set it to the user with that identity? I am just using objectId because that ties to my objectId for a record of data in parse.com, just an extra property, but I did not realize that distinct_id would tie it to a user in mixpanel.

@carlsverre

This comment has been minimized.

Copy link
Contributor

commented Dec 14, 2012

Yes, for us to track users you must use certain property names. distinct_id is the property name we use to track users. There is no way for us to know which property name you want the user's id to be, which is why we have this requirement.

Here are all our special property names that you can use: https://mixpanel.com/docs/properties-or-segments/special-or-reserved-properties

@bwship

This comment has been minimized.

Copy link
Author

commented Dec 14, 2012

Cool, I will try this out. The distinct_id on a track event can be used instead of identify in all cases then, if i would choose to do it that way?

@carlsverre

This comment has been minimized.

Copy link
Contributor

commented Dec 14, 2012

In the node.js library, you should attach a distinct_id property to every track call that you want to tie to a user. On the client side, our js library provides the identify() function to make this easier. You should use the identify() function on the client side always, especially considering that on the client side you shouldn't be tracking data for more than the current user.

@bwship

This comment has been minimized.

Copy link
Author

commented Dec 14, 2012

Yup, that is perfect. Yea, the entire reason I am then calling some ndoe code is to track this event for a different user, and since I already used .identoify client side for the currrent user, this seemed like a solid solution. Thanks a lot for the help. Mixpanel is really rocking!

@mividtim

This comment has been minimized.

Copy link

commented Mar 22, 2016

Can I set distinct_id on a people.set call? When I do, it seems to create no users in Mixpanel. Is there no way to create a user, specifying the distinct_id for that user, with this library?

@mividtim

This comment has been minimized.

Copy link

commented Mar 22, 2016

I just found in the docs that I should be setting the $distinct_id property, not distinct_id, on people.set calls. It would be great if the README included this property in the user-creation example. There is really no circumstance I can think of using this Node library where you wouldn't want to specify your own. Otherwise, how would you know what value to use on subsequent tracking calls? You wouldn't be able to figure out the ID mixpanel created, since you have no user context.

@adelespinasse

This comment has been minimized.

Copy link

commented Nov 29, 2016

@mividtim Saying you need to set $distinct_id is misleading (or possibly the library has changed since you wrote that). You actually need to pass the distinct_id value as the first parameter of people.set, and other properties in the second parameter. So don't do:

mixpanel.people.set({
  $distinct_id: userId,
  name: name
});

Do this instead:

mixpanel.people.set(
  userId,
  { name: name }
);

I wish the documentation was more clear about the differences between this package and mixpanel-browser. The only place it's really clear is in the code itself:

https://github.com/mixpanel/mixpanel-node/blob/master/lib/mixpanel-node.js#L352

@mividtim

This comment has been minimized.

Copy link

commented Nov 29, 2016

Interesting. I haven't tested this code in a while, but it's not throwing errors and marketing isn't complaining. It did work with setting $distinct_id right in the properties at the time I wrote that comment, and may still work now. I got the special property name from your documentation here:

https://mixpanel.com/help/questions/articles/special-or-reserved-properties

That's how it's documented, and it seems to work.

@adelespinasse

This comment has been minimized.

Copy link

commented Nov 30, 2016

Well, it didn't work for me. Maybe it would work to set $distinct_id in the properties as long as the properties were the second argument. (Unless you're using mixpanel-browser, in which case it's the first argument, as shown in most of the docs; but then you generally don't need to set $distinct_id in people.set or mixpanel.track because you can set it once with mixpanel.identify.)

I'd seen that documentation page, but it doesn't show the order of arguments for people.set (or even mention people.set), just the special property names for people records in general.

(I'm not affiliated with Mixpanel, in case that wasn't clear; just a user trying to clear up some confusion.)

@aviadbd

This comment has been minimized.

Copy link

commented Jan 28, 2019

I think its possible to create a method Mixpanel#identify(id) which returns an object with all the mixpanel methods, just automatically adding the id. That way it can be passed along to downward components who dont need to figure out the distinct_id by themselves. I've done something like that for my own application needs, if anyone's interested in code examples, but I think its fairly simple and better done within the API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.