I have a simple web page hosted in an EC2 machine, using nginx. Let's say my web page is reachable by:


I've put a Google Analytics tracking code inside my page, in the head section. After that, I've bought a domain name, and redirected it to the above address.

I've used the "invisible redirection" of my domain provider, to avoid showing the IP in the address bar, and show the domain name instead. As result, my domain provider construct a web page with a frameset that contains the real URL of my site. This way:

    <FRAME SRC="http://<my_ec2_machine_static_ip>/my_web_page" NORESIZE>

The Analytics support page for framed sites says: "We recommend that a site using frames includes the tracking code in the <head> section of the frameset (parent) page, as well as directly before the </head> tag of each child frame that you want to track."

The problem is I don't have access to the "parent" page (the page that contains the frameset code above). I just have access to my page. So, I can't put the tracking code in this "parent" page.

Is there a cleaner way of doing this? Am I going to get fake statistics for this reason?

Many thanks in advance

2 Answers 2


I try this and it works for me:

Insert the script code below at the end of your HTML code, just before the tag:

        var _gaq=[['_setAccount','UA-XXXXXXXX-X'],['_trackPageview']];
        (function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];

Change UA-XXXXXXXX-X with you tracking ID.

I prefer use this code from Initializr Template, because the Analytics code from Google, not working for me.

I've hope helped you :)

  • I don't believe this would actually work in his situation: with a framed redirect from his domain name to an IP address. There is nothing in there that even sets the domain name. May 15, 2013 at 18:01
  • 1
    Seems to work for me too... May 15, 2013 at 18:28
  • @StephenOstermiller I know it's strange, but this way works and I can collect statistics of my website. May 16, 2013 at 10:55
  • Glad to have confirmation. Upvoting as useful. May 16, 2013 at 11:00

Since you are using Amazon, there is no reason for you to use your domain providers "invisible redirection". Instead you should:

  1. Sign up for Amazon AWS Route 53 DNS Service
  2. In route 53, create a "Hosted Zone" for your domain
  3. Add an A records for both .yourdomain.com and www.yourdomain.com with the static IP address of your ec2 machine.
  4. Go to your domain provider and set the nameservers for your domain to the records in the NS section of Amazon Route 53.

Then you will have your domain name pointed at your ec2 server properly. No redirects or frames needed. Your site will be able to work with analytics.

  • Thanks for your response! I'm actually in the AWS free tier for 1 year. I'm not sure it the Route 53 DNS service is included or has any cost. I'll check it. May 15, 2013 at 18:24
  • Even if it isn't free, it isn't expensive. It should be about the same as the cost of domain registration. Another alternative would be to use zonomi.com I use route 53 for one of my domains and zonomi for the rest. Zonomi has the same functionality as route 53 and a has a free level of service for a single domain. May 15, 2013 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.