I have a software that I must host in an external server in a niche market (kind of extensions for browsers). I want to know how many people click on the link when I share it on social media.
My idea is to redirect a post in my site to it, but before the redirection happens the Google Analytics script should be fired, so that I get the report. The Redirection plugin can be used for redirection, but it doesn't support that yet. One go-around idea is to create a post and add this:
window.location.replace("");
but it may increase the loading time for loading the header. Plus that it doesn't guarantee that the script will be fired, as it can be included at the footer.
Is there a way to make sure that the script is fired before redirection?
I have a software that I must host in an external server in a niche market (kind of extensions for browsers). I want to know how many people click on the link when I share it on social media.
My idea is to redirect a post in my site to it, but before the redirection happens the Google Analytics script should be fired, so that I get the report. The Redirection plugin can be used for redirection, but it doesn't support that yet. One go-around idea is to create a post and add this:
window.location.replace("http://stackoverflow");
but it may increase the loading time for loading the header. Plus that it doesn't guarantee that the script will be fired, as it can be included at the footer.
Is there a way to make sure that the script is fired before redirection?
Place both scripts in the footer. In order, put Google scripts first, wrap in a promise, then add:
.then(
function(response){
window.location.href = 'http://www.google'; //for example
},function(error){
console.log('Error: ' + error.statusText);
}
);