I am trying to use Facebook conversion code like below that includes
both scripts and noscripts tags:
<html>
<head>
<script type="text/javascript">
// Wait for the page to load first
window.onload = function() {
//Get a reference to the link on the page
// with an id of "mylink"
var a = document.getElementById("mylink");
//Set code to run when the link is clicked
// by assigning a function to "onclick"
a.onclick = function() {
// Code to be executed when the link is clicked.
var _fbq = window._fbq || (window._fbq = []);
...
}
}
</script>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=6030151253043&cd[value]=0.00&cd[currency]=USD&noscript=1" /></noscript>
</head>
<body>
<a id="mylink" href="http://example.com">Link</a>
</body>
</html>
Usually I can put this code in a thank you page in my website. But now I have a situation that I want to track if someone clicks an external link which leads to some external webpage that is out of my control. My page should not execute this conversion code when it loads but only when the link is clicked.
For example, my page has a link that goes to http://example.com, so when a user clicks this link, this conversion code can be executed and then go to http://example.com?
The problem is that when the browser does not support JavaScript, the code inside noscript tag will execute even if the link was not clicked.
Is there any way to solve that problem?