Question

How to use alias in Backend

  • 29 December 2020
  • 3 replies
  • 66 views

We use to track event in App only, now we want to integrate and track event at Backend also(to get a more accurate event tracking since some event happen only on backend side)

We have read through most of the doc in the internet but we are still very unclear on how should we be able to track event at backend. We have saw a lot of document urging us to create alias for a distinct id, but there are none describing how can we use it on backend where there are no identify method for us to call🙈

Simply say, given we create an alias `HK#1234` for a distinct id `xxxxxxxxxxxxx`, can we just track event with distinct_id assigned to `HK#1234` in Backend SDK/API call?

# given distinct_id = 'xxxxxxxxxxxx'
# and alias 'HK#1234' is created for this distinct_id

require 'mixpanel-ruby'

tracker = Mixpanel::Tracker.new(project_token)
result = tracker.track('HK#1234', event_name, properties)


FYI:

  1. we are using ruby in BE and we are using the gem `mixpanel-ruby`.
  2. we do not keep the original random string’s distinct_id since this is from client side and we really don’t want to do so.

3 replies

Userlevel 3
Badge +1

Are you likely to send anonymous user events from backend on only logged in users’?

If latter, then all you need to ensure is that alias or identify has been called with your internal user id once  before any backend events are sent. After that just ensure that backend events use your internal id.

Sending anonymous events form backend is more tricky. In this case you will have to somehow store the Mixpanel anonymous disctinct id is the backend and send events with that. Not a very clean thing to do, but can’t think of another way to make this work.

Thanks Jaya for the quick response. We are more on the latter case you mentioned. we won’t send anonymous user events in backend.
One thing we are still very puzzling is that we are not going to create alias at the backend(this should be created on app side already) and I believe there are no way for backend to call identify(there are no such API provided, plus this doesn’t make sense to do so since Backend will not handle only one identity)

So what I would like to confirm is that whether the internal user ID(already a alias of distinct_id) can be used as the distinct id directly since we have to provide specific distinct_id on each tracking call(this is something different with client side since a single client always represent single identity, but this is not the case for backend)

quite the code again:

# given distinct_id = 'xxxxxxxxxxxx'
# and alias 'HK#1234' is created for this distinct_id

require 'mixpanel-ruby'

tracker = Mixpanel::Tracker.new(project_token)
result = tracker.track('HK#8964', event_name, properties)

 

Userlevel 3
Badge +1

Yes. Alias needs to be called only once. And if FE has already called it to link anonymous id with your internal id, then your backend events can totally use your internal id while sending events. That would be the clean and right thing to do indeed.

Reply


Mixpanel