Question

Having a unified view of the user journey, with events from JS and PHP.


  • New Participant
  • 2 replies

Hi there!
I’m implementing MixPanel on my SaaS and trying to figure out how this things work ;) I’m implementing by an hybrid of JS and PHP.
When a user signs up [registered via PHP], the previous and after events [via JS] such as “Location Viewed” don’t merge. This way I dont have a unified view on the user journey. Please any idea on how make it happen?

 

This is how Im sending the events:

 

This is the current output I get:

 

Thanks a lot for the help!


5 replies

Userlevel 5
Badge +4

Hi @leo,

What I am understanding is that your Distinct_id “78” that is captured on the server-side PHP implementation event “sign up” is not following the user when they trigger event “Location Viewed” on the Javascript end? If so, on hybrid implementations you have to make sure that you carry over the distinct_Id from one library to the other for it follow the users journey on your application. Is this something you are doing by any chance? Would you mind sharing it? Maybe I can take a stab on what is happening. 

Going of the code you have shared, I can only see that you are setting your own distinct_id under $lastUid php variable and then passing it on the php event  $mp→track(“Sign”). I cannot see how you are calling the “Location Viewed” event in Javascript but the main variable that needs to be carried over is the $lastUid into your JS events to keep the user flow consistent. 

I looked in Stackoverflow how to get PHP and Javascript to communicate with each other and found this post that could be a good starting point. 

Hi @stephanie,

 

Thanks for the prompt answer! I had no idea I should carry the DistinctID myself between both implementations…

 

My Location Viewed is simply a mixpanel.track call (screenshot). If I understood correctly I should pass somehow the PHP variable to JS such as below?

mixpanel.identify(<?php echo”$lastUid”; ?>);

 

 

 

Thanks!

Good news @stephanie , Im managing to pass the Distinct ID to JS/Location Viewed ;) Thanks for the suggestion.

Now, wasn’t supposed to all previous sessions (“15 mins ago”) to be updated as well? Would be awesome to recreate the user steps and analyse how they convert.

 

Thanks again!

 

 

Userlevel 5
Badge +4

Hi @leo,

Great to hear you were able to pass your distinct ID over. Would you mind sharing your new code on your Mixpanel.track() call on your front end or possible Github repo to look at? Right now I can only see your previous front-end call.

In the meantime, I wanted to share a server-side identity management article that shows how to maintain a user’s identity in hybrid server-side and client-side implementations - the example is in Javascript and PHP. It also provides insights and strategies to ensure the identity of a user remains consistent through the interactions made with your site or app.

Hi @stephanie !

Thanks again or your help. Leo still, had to use another account due to SSO updates ;)

Im sending attached the updated JS code, used only on the confirmation page [confirm-email.php]. As I was assuming that’s the only moment thats necessary to integrate both libraries. [Side note: I’m terrible with JS. The more I can do on PHP-side the merrier. Maybe even parsing the cookie to get the distinctID - something not recommended on the article you shared ;)]

 

 

Would be great to share my repo, can I do that privately for your email by any chance?

Thanks a lot!

Stepping back a bit, let me share my implementation plan with the Client/Server and the functions that, according to my understanding so far, should be called. Would be amazing to hear your thoughts if something is off.

- Visit/Client OK
- Signed up>email/Server OK
$mp->track(“Signup”);
$mp->alias($email); // To assign to visitors' DistinctID XX
$mp->people.set($email, $signupDate); OK
+ Pass the $lastID from PHP to JS. OK

- Logged in>email, date/Server
$mp->track(“Login”); OK
$mp->identify($email); OK

- Add first server/Server
    Served added > hostname
    $mp->track(“Server Added”, array(“hostname” => “$hostname"));
    $mp->track(“Server Deleted”, array(“hostname” => “$hostname"));

    [Until adding the 6th server, so a paid plan is necessary] 

    - Checkout completed/Server
    Upgrade account successfully [paid via Stripe/Paddle]

----

- Engage with email notifications [messages read X times] ?
UTM email link OK

- Setup an integration [Jira, Slack, etc]
- Paywall opened/closed [Served limit reached]

Reply