HasanG
HasanG

Reputation: 13161

How to skip Google Analytics loading?

Turkish government have blocked some IPs including Google Analytics. This caused all the web sites using alanytics to slow down and even not to load. How can we prevent this problem? How can we skip loading of ga.js if not available?

Upvotes: 7

Views: 904

Answers (4)

Andy E
Andy E

Reputation: 344565

You could try using the defer attribute on a script element to delay loading until the document has been fully parsed.

<script src="http://www.google.com/path/to/analytics.js" 
        type="text/javascript"
        defer>
</script>

I'm not sure if this would affect the analytics scripts adversely, though.

As an aside, the defer attribute is available in newer versions of Firefox, IE6+, Chrome, Safari, Opera.

Upvotes: 2

Mads Mogensh&#248;j
Mads Mogensh&#248;j

Reputation: 2068

Google offers an asynchronous snippet for their tracking code:

Note that you need to use a different tracking syntax to use it, check the migration guide on the link for details. It also require a browser with support for the HTML5 attribute 'async', so it may not fully solve your problem.

Another solution is proposed in 'Better Google Analytics JavaScript that doesn't block page downloading'

Upvotes: 6

bogdan
bogdan

Reputation: 671

You can try using the loading the GA script asynchronously

Upvotes: 1

Douglas Leeder
Douglas Leeder

Reputation: 53310

It depends how the Turkish government is blocking:

  1. Connections hang
  2. Connections are refused
  3. Packets just black-hole

It's probably 3), so you'll have to detect Turkish IPs and write the page differently to not reference google to fix the problem. At least that's the only solution I can think of at the moment.

Upvotes: 1

Related Questions