Changelog · Cloudflare Zaraz docs

It seems the internals of Zaraz tracking SPAs changed in the last month or so, perhaps breaking the previous implementations. In Dec 2023 @yo'av recommended an approach like this:
window.zarazData['l'] = document.location.href;
window.zarazData['t'] = document.title;
window.zarazData['r'] = prevLocation;
window.zaraz.pageVariables = {};
window.zaraz.track('__zarazSPA');
window.zarazData['l'] = document.location.href;
window.zarazData['t'] = document.title;
window.zarazData['r'] = prevLocation;
window.zaraz.pageVariables = {};
window.zaraz.track('__zarazSPA');
but now I see zaraz.spaPageview() was released in Feb 2024 https://developers.cloudflare.com/zaraz/changelog/#2024-02-15 and it appears that perhaps the prior approach is not working correctly anymore? I searched this discord and there were zero mentions of spaPageview()
Cloudflare Docs
Changelog · Cloudflare Zaraz docs
Run third-party tools and services on the cloud, and improve the loading speed and security of your website.
2 Replies
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
BensTechLab
BensTechLabOP10mo ago
Thanks Yo'av. I was missing analytics events and trying to debug. The problem was on my end to do with scope of re-rendering in nextjs/react. That said I did find the documentation lacking for spaPageview() so I couldn't tell if it was exactly equivalent to the above sample code in terms of recognizing the referrer and current page title if those changes in a soft navigation. If the old way continues to work, I won't change it. But if you want more people to be using the new way, I'm happy to go further. Separate Issue/Side Effect of learning above: Interestingly I've learned a lot about the Zaraz debugger on a nextjs/react site where if it re-renders the body element it will also destroy the zaraz debugger UI. In my case the body element is not in my root layout file as I change the body element attributes on various pages of the site. This causes react to re-render the body element and will also destroy the zaraz debugger if open. I never really knew why this happened before, now I do. I could build something in react to overcome this - but curious if you had any well known approach to this already.

Did you find this page helpful?