1 | <?php |
---|
2 | |
---|
3 | if (!defined("_ECRIRE_INC_VERSION")) return; |
---|
4 | |
---|
5 | |
---|
6 | /** |
---|
7 | * Dans SPIP 3 on utilise insert_head_css qui est safe |
---|
8 | * et on insere avant les CSS, pour ne pas bloquer celles-ci |
---|
9 | * (qui sont bloquees par du js inline) |
---|
10 | * |
---|
11 | * @param $flux |
---|
12 | * @return string |
---|
13 | */ |
---|
14 | function googleanalytics_insert_head_css($flux) { |
---|
15 | return $flux . googleanalytics_snippet(); |
---|
16 | } |
---|
17 | |
---|
18 | /** |
---|
19 | * Dans SPIP 2 on utilise insert_head et on ajoute a la fin |
---|
20 | * simplement |
---|
21 | * |
---|
22 | * @param $flux |
---|
23 | * @return string |
---|
24 | */ |
---|
25 | function googleanalytics_insert_head($flux) { |
---|
26 | return $flux . googleanalytics_snippet(); |
---|
27 | } |
---|
28 | |
---|
29 | /** |
---|
30 | * Morceau de code a inserer dans la page pour traquer avec GA |
---|
31 | * @return string |
---|
32 | */ |
---|
33 | function googleanalytics_snippet(){ |
---|
34 | include_spip('inc/config'); |
---|
35 | $id_google = lire_config('googleanalytics/idGoogle'); |
---|
36 | $cookiebar = (isset($_COOKIE["cb-enabled"]) ? $_COOKIE["cb-enabled"] : ''); |
---|
37 | $displayCookieConsent = (isset($_COOKIE["displayCookieConsent"]) ? $_COOKIE["displayCookieConsent"] : 'y'); |
---|
38 | if ($id_google |
---|
39 | AND $id_google !== '_' |
---|
40 | AND (strncmp($id_google,"UA-xxx",6) != '0') |
---|
41 | AND $cookiebar !== 'declined' |
---|
42 | AND $displayCookieConsent === 'y') { |
---|
43 | if (lire_config('googleanalytics/ga_universal')) { |
---|
44 | return "<script type='text/javascript'>/*<![CDATA[*/ |
---|
45 | (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) }) |
---|
46 | (window,document,'script','//www.google-analytics.com/analytics.js','ga'); |
---|
47 | ga('create', '".$id_google."'); |
---|
48 | ga('send', 'pageview'); |
---|
49 | /*]]>*/</script>\n"; |
---|
50 | } else { |
---|
51 | return '<script type="text/javascript">/*<![CDATA[*/ |
---|
52 | var _gaq = _gaq || []; |
---|
53 | _gaq.push(["_setAccount", "'.$id_google.'"]); |
---|
54 | _gaq.push(["_trackPageview"]); |
---|
55 | (function() { |
---|
56 | var ga = document.createElement("script"); ga.type = "text/javascript"; ga.async = true; |
---|
57 | ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js"; |
---|
58 | var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ga, s); |
---|
59 | })(); |
---|
60 | /*]]>*/</script>'."\n"; |
---|
61 | } |
---|
62 | } |
---|
63 | return ""; |
---|
64 | } |
---|
65 | ?> |
---|