Hi,
My webflow website has pages with a redirect in the custom code, with a 0.5 delay so that they still show up as page visits. Since a while, they don’t show anymore. Any idea why?
Somehow, it seems to work now. Don’t know whether this was a temporary bug, or the functionality was restored in the meantime.
You should never expect analytics data to be send when just waiting .5 seconds.
Maybe this works?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Track and redirect</title>
<!-- 1. Placeholder snippet + trackAndRedirect in a single script -->
<script>
// Simple Analytics placeholder
window.sa_event = window.sa_event || function () {
const args = [].slice.call(arguments)
if (window.sa_event.q) {
window.sa_event.q.push(args)
} else {
window.sa_event.q = [args]
}
}
/**
* @param {string} eventName - The name of the Simple Analytics event.
* @param {string} redirectUrl - The URL to redirect to.
* @return {void}
*/
const trackAndRedirect = async ({ eventName, redirectUrl }) => {
let redirected = false
const doRedirect = () => {
if (!redirected) {
redirected = true
window.location.href = redirectUrl
}
}
const timeout = setTimeout(doRedirect, 3000)
try {
if (window.sa_loaded) {
window.sa_event(eventName, () => {
clearTimeout(timeout)
doRedirect()
})
} else {
clearTimeout(timeout)
doRedirect()
}
} catch (error) {
clearTimeout(timeout)
doRedirect()
}
}
// Example usage
window.addEventListener("load", () => {
trackAndRedirect({
eventName: "clicked_signup",
redirectUrl: "https://example.com"
})
})
</script>
</head>
<body>
<!-- 2. Simple Analytics script -->
<script async src="https://scripts.simpleanalyticscdn.com/latest.js"></script>
</body>
</html>
Hey Adriaan,
thanks for your reply. It somehow works again; I’ve set a delay on the webflow page and it shows in SA.