Skip to main content
Solved

handling log in / log out within a SPA


Forum|alt.badge.img+3

How do we leverage the front-end Identify API to handle when users log in and log out within a Single-Page Application (Angular) without refreshing the page? It seems that the 'identify' method is having issues being recognized properly when called multiple times per page load.

Best answer by stephen.trumble

Hey @reephmarketing 

Thank you for clarifying. Unfortunately Klaviyo currently does not support single page applications. I also was able to see that a feature request was put in with our product team on your behalf. If and when there is an update i will update you in this thread! Thank you for your patience and being part of the Klaviyo Community.

View original
Did this topic or the replies in the thread help you find an answer to your question?

3 replies

stephen.trumble
Community Manager
Forum|alt.badge.img+60

Hey @reephmarketing 

Welcome to the Klaviyo Community! Thank you for asking the community for help.

Essentially, because of a change we made last year to our cookies, that identify call needs to fully resolve before a track call can be made, so that the user is properly cookied, as a cookie is needed for client-side track events to properly be accepted by your Klaviyo account.

Adding this to your code should help with this situation:  

function onIdentifyCompleteCallback () {
  _learnq.track("Neat Event");
}

_learnq.identify(identityProperties, undefined, undefined, onIdentifyCompleteCallback);

 
"Neat Event" should be replaced with the event you're attempting to track. If you are not the person who created this event for your company, I would advise you pass this info along to the person or people who did. This isn't the only way to accomplish this task, there are others. As long as you're allowing the Identify event to fully resolve before sending over the track event, you should start to see a track event fire every time.

Hope this helps! Thanks again for being part of the Klaviyo Community!


Forum|alt.badge.img+3

Hi Stephen,

 

Thanks so much for your feedback and thoughts. I didn’t do a great job explaining the issue I’m encountering, and that’s on me.

For further color - we need to call the 'identify' method a second time for when a new user logs in. User A logs in, we call the identify method with user A's info. User A logs out.  User B logs in. We call the identify method with user B's info, but the Klaviyo integration (within our Angular app) still thinks user A is logged in because the page/app never refreshes during these steps. I don’t think the issue is related to the tracking method, but maybe it is. We end up with User B doing some things on our website but the Klaviyo integration is attributing those actions to User A. 

Really appreciate your help.


stephen.trumble
Community Manager
Forum|alt.badge.img+60

Hey @reephmarketing 

Thank you for clarifying. Unfortunately Klaviyo currently does not support single page applications. I also was able to see that a feature request was put in with our product team on your behalf. If and when there is an update i will update you in this thread! Thank you for your patience and being part of the Klaviyo Community.