My goal is to track conversion rates for my Google Adwords campaign and regular traffic directed to the App Store. Initially, I had a link "/app_store/" on my page that would lead visitors to the app store after a 1-second delay.
I came across a more sophisticated solution using Javascript. For Adwords, it loads a pixel image and for analytics, it triggers a Google Javascript function, briefly pauses, and then redirects to the link.
Unfortunately, this setup isn't yielding results for me. Both Google Analytics and Google Adsense are not registering any visits to the App Store (not even when I test it myself).
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-18180332-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
function recordOutboundLink(link, category, action) {
try{
// Google Analytics
var pageTracker = _gat._getTracker("UA-18180332-1");
pageTracker._trackEvent(category, action);
// Google Adwords
var image = new Image(1, 1);
image.src = "http://www.googleadservices.com/pagead/conversion/1046551421/?value=$8&label=zqrfCMWh0QEQ_baE8wM&guid=ON&script=0"
setTimeout('document.location = "' + link.href + '"', 100)
} catch(err) {}
}
</script>
For the link:
<a href="http://itunes.apple.com/ae/app/isimplifiedchinese/id377690407?mt=8"
onClick="recordOutboundLink(this, 'Outbound Links', 'http://itunes.apple.com/ae/app/isimplifiedchinese/id377690407?mt=8');return false;">
<img alt="Appstore" src="images/appstore.png"></a>
Any ideas on what might be going wrong here?
Update 23:13 I noticed that with a 100ms delay, I encountered an error message briefly flashing on the screen (took some time to capture in a screenshot).
I only tested this with Erwan's suggestion; unsure if this also occurred in the previous version. The error seems to disappear with longer delays; hence, I increased it to 300ms for precaution.