Is there a way to stop Google Analytics counting development work as hits?

后端 未结 22 1660
终归单人心
终归单人心 2020-12-02 04:51

I have added the JavaScript that I need to the bottom of my pages so that I can make use of Google Analytics. Only problem is that I am sure that it is counting all my devel

相关标签:
22条回答
  • 2020-12-02 05:24

    We setup a 2nd google analytics tracking code for development and QA work -- actually comes in handy when you want to test your analytics integration, also ensures one doesn't have bleedover into production stats.

    0 讨论(0)
  • 2020-12-02 05:26

    Probably not helpful to you, but I solved this problem by writing a custom ASP.NET server control that injects the required JavaScript. I then added the live URL to web.config and then only made the control visible when the host name matched the live URL in web.config.

    0 讨论(0)
  • 2020-12-02 05:27

    Yeah, you go into Analytics Settings, edit your site, and +Add Filter to define a filter that excludes your IP address.

    Past data is not regenerated with filters applied, so you'll only have the benefit of them moving forward.

    0 讨论(0)
  • 2020-12-02 05:27

    I like the simple approach of using javascript. It works anywhere.

    <script type="text/javascript">
    if (document.location.hostname.search("myproductiondomainname.com") !== -1) {
    
    //google analytics code goes here
    
    }
    </script>
    
    0 讨论(0)
  • 2020-12-02 05:27

    Add this line before your Google Analytics async code runs to disable tracking for that web property ID:

    window['ga-disable-UA-XXXXXX-Y'] = true;
    

    UA-XXXXXX-Y corresponds to the web property ID on which you would like to disable tracking.

    From: https://developers.google.com/analytics/devguides/collection/gajs/

    0 讨论(0)
  • 2020-12-02 05:28

    Like people are mentioning you can either host the google-analytics.com domain locally or setup a function to see if you are working in your development network.

    Keep in mind if http://www.google-analytics.com/ga.js does not load and your using onclick javascript functions to help track clicks on page elements.

    IE: onclick="javascript:pageTracker._trackPageview('/made/up/folder/reference');

    Your going to have JavaScript errors that will stop jQuery or other robust JavaScript functions from functioning.

    0 讨论(0)
提交回复
热议问题