Giter VIP home page Giter VIP logo

Comments (18)

adelespinasse avatar adelespinasse commented on August 15, 2024 4

@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

from mixpanel-node.

mividtim avatar mividtim commented on August 15, 2024 3

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.

from mixpanel-node.

aviadbd avatar aviadbd commented on August 15, 2024 2

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.

from mixpanel-node.

carlsverre avatar carlsverre commented on August 15, 2024 1

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"
});

from mixpanel-node.

andirsun avatar andirsun commented on August 15, 2024 1

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.

from mixpanel-node.

bwship avatar bwship commented on August 15, 2024

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.

from mixpanel-node.

carlsverre avatar carlsverre commented on August 15, 2024

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.

from mixpanel-node.

bwship avatar bwship commented on August 15, 2024

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.

from mixpanel-node.

carlsverre avatar carlsverre commented on August 15, 2024

Why are you setting objectId and not distinct_id?

from mixpanel-node.

carlsverre avatar carlsverre commented on August 15, 2024

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

from mixpanel-node.

bwship avatar bwship commented on August 15, 2024

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.

from mixpanel-node.

carlsverre avatar carlsverre commented on August 15, 2024

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

from mixpanel-node.

bwship avatar bwship commented on August 15, 2024

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?

from mixpanel-node.

carlsverre avatar carlsverre commented on August 15, 2024

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.

from mixpanel-node.

bwship avatar bwship commented on August 15, 2024

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!

from mixpanel-node.

mividtim avatar mividtim commented on August 15, 2024

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?

from mixpanel-node.

mividtim avatar mividtim commented on August 15, 2024

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.

from mixpanel-node.

adelespinasse avatar adelespinasse commented on August 15, 2024

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.)

from mixpanel-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.