If you have a single-page app where content is swapped out on the client side but without any page refreshes, you'll need to split up the Castle.js integration into multiple steps.
Once you have a logged the user into your site via an asynchronous API call, you'll call the following from your single-page app. You’ll also need to track a page view after the call to make sure the user ID is tracked to Castle.
_castle('identify', response.user.id); _castle('trackPageview');
Since we’ve now turned off
autoTrack, you will need to call the following in order to track a page view every time the URL changes. It’s recommended that you only track this for full view transitions, and for example not in-page updates to the URL hash.
In a similar way to how you logged in the user, you’ll also need to reset the state on logout. Finish it up by tracking a page view to ensure the reset call reaches the Castle API.
The guide for Secure Mode mentions rendering the secure token into the HTML code, but since the user won't be logged in during page load, this approach is not an option for single-page apps. Instead you'll need to return generate the secure token during the login call and then call the following right after
_castle('identify', response.user.id); _castle('secure', response.token); _castle('trackPageview');