Closed bwship closed 11 years ago
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"
});
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.
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.
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
If I simply set the objectId in the track event, this tracking item never gets assigned to that user.
Why are you setting objectId and not distinct_id?
Also, you might want to make sure you set the name_tag
property as well to be the name of user 1.
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.
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
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?
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.
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!
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?
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.
@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
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.
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.)
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.
If someone still interested, is possible to identify anonymous users on backend library. You can use track method and send an event with $identify as eventName
... Do this when your user sign-up/sign-in
mixpanel.track('$identify',{
$identified_id: <Use your user.id>,
$anon_id: <Use the device_id from frontend library eg: $device:1231-12312-132>,
})
This will act as a regular mixpanel.identify method available on frontend library.
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
Thanks, Bob