From 720eb0aaa143011c2c705d98de49522bdb48818a Mon Sep 17 00:00:00 2001 From: Amauri CHAMPEAUX Date: Sat, 30 Jun 2018 08:53:37 +0200 Subject: [PATCH] Add a service to use multiple Google Analytics If you need to add multiple gtag.js tracker, use this services and pass a JavaScript array to tarteaucitron.user.multiplegtagUa = ['UA-XXXXXXXX', 'UA-XXXXXXXX']; --- tarteaucitron.services.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tarteaucitron.services.js b/tarteaucitron.services.js index ba771ea..03e1955 100644 --- a/tarteaucitron.services.js +++ b/tarteaucitron.services.js @@ -2165,3 +2165,38 @@ tarteaucitron.services.webmecanik = { }); } }; + +// google analytics multiple +tarteaucitron.services.multiplegtag = { + "key": "multiplegtag", + "type": "analytic", + "name": "Google Analytics (gtag.js)", + "uri": "https://support.google.com/analytics/answer/6004245", + "needConsent": true, + "cookies": (function () { + + var cookies = ['_ga', '_gat', '_gid', '__utma', '__utmb', '__utmc', '__utmt', '__utmz']; + + if (tarteaucitron.user.multiplegtagUa !== undefined) { + tarteaucitron.user.multiplegtagUa.forEach(function(ua) { + cookies.push('_gat_gtag_' + ua.replace(/-/g, '_')); + }); + } + + return cookies; + })(), + "js": function () { + "use strict"; + window.dataLayer = window.dataLayer || []; + + tarteaucitron.user.multiplegtagUa.forEach(function(ua) { + + tarteaucitron.addScript('https://www.googletagmanager.com/gtag/js?id=' + ua, '', function () { + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); + gtag('config', ua); + }); + }); + } +}; +