浏览代码

Enhance Universal Analytics :
* add ability to set additional fields on "create" method (https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#create)
* add ability to set anonymizeIP to true (https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#anonymizeIp)
* add ability to set path to "pageview" method (https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#page)

bchatard 6 年之前
父节点
当前提交
ee329bed34
共有 1 个文件被更改,包括 14 次插入2 次删除
  1. 14 2
      tarteaucitron.services.js

+ 14 - 2
tarteaucitron.services.js

@@ -1047,8 +1047,20 @@ tarteaucitron.services.analytics = {
         };
         window.ga.l = new Date();
         tarteaucitron.addScript('https://www.google-analytics.com/analytics.js', '', function () {
-            ga('create', tarteaucitron.user.analyticsUa, {'cookieExpires': 34128000});
-            ga('send', 'pageview');
+            var uaCreate = {'cookieExpires': 34128000};
+            tarteaucitron.extend(uaCreate, tarteaucitron.user.analyticsUaCreate || {});
+            ga('create', tarteaucitron.user.analyticsUa, createConfig);
+
+            if (tarteaucitron.user.analyticsAnonymizeIp) {
+                ga('set', 'anonymizeIp', true);
+            }
+
+            if (tarteaucitron.user.analyticsPageView) {
+                ga('send', 'pageview', tarteaucitron.user.analyticsPageView);
+            } else {
+                ga('send', 'pageview');
+            }
+
             if (typeof tarteaucitron.user.analyticsMore === 'function') {
                 tarteaucitron.user.analyticsMore();
             }