Track a Mixpanel user across subdomains

595 views Asked by At

I have a WordPress marketing site and a Rails web application. A user starts their session on the WP site, and then progresses to the Rails site.

I want to track conversions from the last WP step to the first Rails step, but Mixpanel doesn't seem to be recognizing that the user is the same user at that point.

How can I track a user in Mixpanel across subdomains?

1

There are 1 answers

1
TimmyCarbone On

Here you go with 2 solutions :

The quick solution is query parameters.

If the user is redirected to the Rails site directly from the WP blog then you can pass the user_id that you set on the WP blog to the Rails site as a query parameter (GET params for example, or headers).

Then, you'll be able to retrieve and set the same user_id in your Rails site and Mixpanel will recognize that it's the same user.

Something cleaner would be to use cookies.

If you have access to the back-end of the WP site, you can create an endpoint that returns the user cookie that the user has on your blog. Then you can call that endpoint from your Rails site.

  • Create a cookie with the user_id on your WP blog
  • Call the cookies endpoint of your WP blog from the Rails site
  • Use the cookie you just retrieved to set the same user_id on your Rails site.

This is a bit like Facebook does.