Browse Source

Adding a gray area...

Amauri CHAMPEAUX 10 years ago
parent
commit
3684c37ab7
2 changed files with 25 additions and 3 deletions
  1. 6 3
      tarteaucitron.js
  2. 19 0
      tarteaucitron.services.js

+ 6 - 3
tarteaucitron.js

@@ -6,8 +6,9 @@ var scripts = document.getElementsByTagName('script'),
     cdn = path.split('/').slice(0, -1).join('/') + '/';
 
 var tarteaucitron = {
-    "showAlertSmall": true, // show the small banner on bottom right ?
-    "autoOpen": false, // auto open the panel with #tarteaucitron hash ?
+    "showAlertSmall": true, // show the small banner on bottom right?
+    "autoOpen": false, // auto open the panel with #tarteaucitron hash?
+    "grayArea": false, // activate the features of the gray area?
     "cdn": cdn,
     "user": {},
     "lang": {},
@@ -184,7 +185,9 @@ var tarteaucitron = {
                         tarteaucitron.state[service.key] = false;
                         tarteaucitron.userInterface.color(service.key, false);
                     } else if (!isResponded) {
-                        if (typeof service.fallback === 'function') {
+                        if (typeof service.grayJs === 'function' && tarteaucitron.grayArea === true) {
+                            service.grayJs();
+                        } else if (typeof service.fallback === 'function') {
                             service.fallback();
                         }
                     }

+ 19 - 0
tarteaucitron.services.js

@@ -145,6 +145,25 @@ tarteaucitron.services.analytics = {
             }
         });
     },
+    "grayJs": function () {
+        "use strict";
+        window.GoogleAnalyticsObject = 'ga';
+        window.ga = window.ga || function () {
+            window.ga.q = window.ga.q || [];
+            window.ga.q.push(arguments);
+        };
+        window.ga.l = new Date();
+        
+        tarteaucitron.addScript('//www.google-analytics.com/analytics.js', '', function () {
+            ga('create', tarteaucitron.user.analyticsUa, {'cookieExpires': 86400});
+            ga('set', 'anonymizeIp', true);
+            ga('set', 'forceSSL', true);
+            ga('send', 'pageview');
+            if (typeof tarteaucitron.user.analyticsMore === 'function') {
+                tarteaucitron.user.analyticsMore();
+            }
+        });
+    },
     "fallback": function () {
         "use strict";
         var cookies = ['_ga', '_gat', '__utma', '__utmb', '__utmc', '__utmt', '__utmz'];