Posts

Posts uit december, 2017 tonen

FXM on Single Page Applications

Pushing route visits I had a usecase where I needed to use FXM in a non-Sitecore Single Page Application. By default, FXM only supports loading its script on page load to push a page visit to Sitecore. However, for an SPA this is not very helpful since after the initial load of the APP it only changes routes and will not push events to FXM. So to support pushing route visits from the SPA to Sitecore analytics I made some slight modifications to the standard FXM beacon script to enable the SPA to push a visit to a route to Sitecore. Of course within the SPA this needs to be supported, so the default beacon script needs to be loaded and below PushRouteEvent method called on each route visit. function PushRouteEvent(){ var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == XMLHttpRequest.DONE) { if (xmlhttp.status == 200) { document.getElementById("myDiv").inner