Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I backed up my website and uploaded it to another server for testing and backup purposes.

Should I remove or edit the Google Analytics snippet from the index.php (which is for the real site), or does it not matter as it's not the same server and url address as the one declared at Google Analytics account?

The reason I don't want to remove it is in case someone forgets about it if they upload the backup to the real site in case the real one breaks. Also I know that if I turn off the website there is no GA snippet, but I need it open so I can easily access and test it so I don't have to write pass all the time.

share|improve this question
    
Good and helpful. Though, you should note that other hostnames may also include search engines or domains that people came from by clicking a link going to the website. In my case i found the cc.bingj.com which is Bing's search engine (I have submitted my website there too). –  Yannis Dran Sep 29 '12 at 12:16
add comment

2 Answers 2

up vote 5 down vote accepted

Go to Audience > Technology > Network > Primary Dimension: Hostname

Look for any other hostnames not associated with your production account. Take note.

Now go to Admin > Profiles and select your site profile. Select Filters tab and Add Filter. Create a new filter with criteria "Exclude" - "Traffic to the hostname" - "that are equal to" and type the dev server hostname in the field. Save and you should be all set keeping the GA code on the other test site without any troubles.

You could also add a quick check on the server to determine the URL and display the GA code only on the production server - best of both worlds.

share|improve this answer
add comment

As Gabriel said. I found this explanation from GA:
Hostname
This is the hostname or domain that visitors used to reach your site. Typically this is your site's domain. For example, if you host your blog on mysite.example.com, then your hostname report will contain mysite.example.com. In some cases, your website might be hosted on other domains, such as when you create a mirror (copy) of your site to host on a domain in another country (e.g. mysite.example.uk). In addition, if someone copies a page from your website directly without modifying any of the source code (including the tracking code) and places that page on their own website, your reports will reflect traffic to that page from that hostname as well. You can use profile filters to ensure that traffic only from allowed hosts reaches your reports.

Another Solution is to add a PhP Code:

    <?php
    // gets the actual environment root URL
    $url = JURI::root();

    // see if is in production environment and, if so, echoes the analytics' script tag
    if (strpos($url, "www.productionenvironment.com") !== false) {
        ?>
            <script type="text/javascript">
              var _gaq = _gaq || [];
              _gaq.push(['_setAccount', 'UA-XXXXX-Y']);
              _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);
              })();
            </script>

        <?php
    }
?> 

Personally I prefer Gabriel's solution as it saves additional code from the website.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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