B
B
b01d2012-02-13 19:30:59
JavaScript
b01d, 2012-02-13 19:30:59

Help with JavaScript

Comrades. Help me with JavaScript.

The essence of the problem is this. There is a code: This is the code for my site from Google Analytics. I should place this code before the closing [/head] tag. With that, I dealt with it. So I need this code NOT to be executed when a user from my local network visits the site . Those. with addresses from the range 192.168.0.1 - 192.168.200.254 (because not everyone has the Internet, and those who do not have the site start to slow down terribly). Help out.
script type="text/jаvаscript"
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-ТУТНАБОРЦИФЕРОК']);
_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




Answer the question

In order to leave comments, you need to log in

7 answer(s)
M
MT, 2012-02-13
@MTonly

Using server-side tools, display a block of code depending on the value of the REMOTE_ADDR server variable, which contains the IP address of the computer that requested the page.

@
@ngreduce, 2012-02-13
_

Also, the simplest option is to put the analytics code before [/body]

F
flight, 2012-02-13
@flight

The simplest solution to the problem is to simply write in the place where you paste the script
. This will solve the problem for all modern browsers.

F
Fastto, 2012-02-13
@Fastto

1. Hang the code on the document ready event
2. Ping the Internet with an asynchronous request with a low latency
3. If everything is ok, execute your code

S
Sergey, 2012-02-13
Protko @Fesor

As you have already suggested above, perhaps.
And you can ping easily and naturally by connecting jQuery, say:

$.ajax({
    'url':'http://ya.ru',
    'success': function(data){
         //Ваш код
     }
});

A
AHDPEu, 2012-02-13
@AHDPEu

As an option, make a second domain for such users and check

(function() {

    if (location.host == "vtoroi.domain.ru"){
         return;
    }

    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);
    })();


Or check the client's ip on the server.

M
markoffko, 2012-02-13
@markoffko

Quite already.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question