From ee329bed34ee5433b36a0014b4644a89222649b6 Mon Sep 17 00:00:00 2001 From: bchatard Date: Mon, 6 Aug 2018 17:41:32 +0100 Subject: [PATCH] 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) --- tarteaucitron.services.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tarteaucitron.services.js b/tarteaucitron.services.js index e85bbb8..7b3be47 100644 --- a/tarteaucitron.services.js +++ b/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(); }