Single Page Apps
Some web properties will be built as Single Page Apps (SPA). SPAs should always be configured and managed by an experienced developer. They represent a series of unique behaviors, many unique to particular frameworks, that can impact how the Lytics JavaScript tag needs to be configured to support the desired use cases.
Version 3 of the Lytics JavaScript tag has been built with SPAs in mind, along with other significant improvements. For most SPAs, there are two important things to consider as routes change:
- What represents the view of a new
page
. - When should the visitor’s profile be reloaded or web-based integrations such as Facebook be updated.
Each of these actions are handled independently with two simple commands.
<script type="text/javascript">
// optional custom function for receiving the full entity each time it is loaded
var doSomethingWithProfile = function(p){
console.log(p.data); // log full data object
}
// the following function represents a fake router for a SPA framework
var onRouteChange = function() {
jstag.pageView(); // tracks a pageView
jstag.loadEntity(doSomethingWithProfile); // refreshes the user profile and all configured integrations
}
</script>