Created
September 19, 2024 07:17
-
-
Save xshapira/336b56921344a53a83ca926d5f4dfcf8 to your computer and use it in GitHub Desktop.
Aweber click tracking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Redirecting...</title> | |
<link rel="stylesheet" href="styles.css"> | |
<script type="text/javascript" defer src="https://analytics.aweber.com/js/awt_analytics.js?id=1OYQT"></script> | |
</head> | |
<body> | |
<script> | |
function trackAndRedirect(destUrl) { | |
return new Promise((resolve) => { | |
if (typeof awt_analytics !== 'undefined') { | |
awt_analytics.record( | |
document.location.href, | |
null, | |
"Clicked link to: " + destUrl, | |
"click" | |
); | |
console.log("Aweber analytics tracking sent"); | |
} else { | |
console.log("Aweber analytics not available"); | |
} | |
setTimeout(resolve, 500); // Wait 500ms to ensure tracking completes | |
}).then(() => { | |
console.log("Redirecting to:", destUrl); | |
window.location.href = destUrl; | |
}); | |
} | |
function handleRedirect() { | |
const urlParams = new URLSearchParams(window.location.search); | |
const destUrl = urlParams.get("dest"); | |
console.log("Destination URL:", destUrl); | |
if (destUrl) { | |
trackAndRedirect(destUrl); | |
} else { | |
console.log("No destination URL provided"); | |
} | |
} | |
// Wait for the DOM to be fully loaded | |
document.addEventListener('DOMContentLoaded', function() { | |
// Give some time for awt_analytics to load | |
setTimeout(handleRedirect, 1000); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment