evolutioncreations.com | wacky wiki fun > Ubuntu > FAQ's > Apache2 > Refreshing HTML Page and Google Analytics Integration

Refreshing HTML Page and Google Analytics Integration

Table of contents
No headers

Lets say you want to create a subdomain, and then route it to a completely different webpage after a predefined length of time, but you want it to execute the Google Analytic code to be able to then track the transaction. How do you do that? 

One way to do that would be to use the META tags to refresh the page. A simple example is:

<html>

<head><META HTTP-EQUIV=Refresh CONTENT="0; URL=http://newwebsiteurl/"></head>
<title></title>

<body>

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%

3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("XX-XXXXXX-XX");
pageTracker._trackPageview();
} catch(err) {}</script>

</body>

</html>

 The variables in the above, you can change is 

 

  • CONTENT
  • URL
  • getTracker
The CONTENT you can set to the number of seconds that it will take before the page will refresh automatically. The URL will be set to the FQDN of the website that you want to redirect to. The getTracker is specific to Google Analytics. You will replace XX-XXXXXX-XX with your ID specific to the profile for your Google Analytics site. You can check this within Google Analytics > Profile Settings > Profile settings for your Website > Check Status to take a look at your code and you can see what your ID is.  

  

  

Tag page
You must login to post a comment.
SourceForge.net