diff --git a/CHANGELOG.md b/CHANGELOG.md index d039768b..9304a9f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * adds scroll position reset on location change (issue #279) * adds "hide if 403" option * fixes QR code URI origin (issue #287) +* adds Google UA support * extends selectable icon sizes (adds 128px, 192px, 256px, 384px) * updates H5BP to 4.3.0 * updates jQuery to 2.1.1 diff --git a/src/_h5ai/client/js/inc/ext/google-analytics.js b/src/_h5ai/client/js/inc/ext/google-analytics.js index 7238d855..e9d4cfe3 100644 --- a/src/_h5ai/client/js/inc/ext/google-analytics.js +++ b/src/_h5ai/client/js/inc/ext/google-analytics.js @@ -1,10 +1,10 @@ -modulejs.define('ext/google-analytics', ['_', 'core/settings'], function (_, allsettings) { +modulejs.define('ext/google-analytics-ga', ['_', 'core/settings'], function (_, allsettings) { var settings = _.extend({ enabled: false, gaq: [] - }, allsettings['google-analytics']), + }, allsettings['google-analytics-ga']), init = function () { @@ -14,10 +14,10 @@ modulejs.define('ext/google-analytics', ['_', 'core/settings'], function (_, all window._gaq = settings.gaq; - var strScript = 'script', + var scriptLiteral = 'script', doc = document, - newScriptTag = doc.createElement(strScript), - firstScriptTag = doc.getElementsByTagName(strScript)[0]; + newScriptTag = doc.createElement(scriptLiteral), + firstScriptTag = doc.getElementsByTagName(scriptLiteral)[0]; newScriptTag.async = true; newScriptTag.src = ('https:' === location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; @@ -26,3 +26,44 @@ modulejs.define('ext/google-analytics', ['_', 'core/settings'], function (_, all init(); }); + + +modulejs.define('ext/google-analytics-ua', ['_', 'core/settings'], function (_, allsettings) { + + var settings = _.extend({ + enabled: false, + calls: [] + }, allsettings['google-analytics-ua']), + + init = function () { + + if (!settings.enabled) { + return; + } + + var win = window, + doc = document, + scriptLiteral = 'script', + id = 'ga', + el, firstScriptElement; + + win.GoogleAnalyticsObject = id; + win[id] = win[id] || function () { + (win[id].q = win[id].q || []).push(arguments); + }; + win[id].l = 1 * new Date(); + + el = doc.createElement(scriptLiteral); + el.async = true; + el.src = '//www.google-analytics.com/analytics.js'; + + firstScriptElement = doc.getElementsByTagName(scriptLiteral)[0]; + firstScriptElement.parentNode.insertBefore(el, firstScriptElement); + + _.each(settings.calls, function (call) { + win[id].apply(win, call); + }); + }; + + init(); +}); diff --git a/src/_h5ai/conf/options.json b/src/_h5ai/conf/options.json index da698f23..52e2ea5e 100644 --- a/src/_h5ai/conf/options.json +++ b/src/_h5ai/conf/options.json @@ -159,13 +159,29 @@ Options ["_trackPageLoadTime"] ] - see: http://support.google.com/googleanalytics/bin/topic.py?hl=en&topic=27612 + see: https://developers.google.com/analytics/devguides/collection/gajs/ */ - "google-analytics": { + "google-analytics-ga": { "enabled": false, "gaq": [] }, + /* + Adds Google Universial Analytics asynchronous tracking code. + + for example: + "calls": [ + ['create', 'UA-XXXX-Y', 'auto'], + ['send', 'pageview'] + ] + + see: https://developers.google.com/analytics/devguides/collection/analyticsjs/ + */ + "google-analytics-ua": { + "enabled": false, + "calls": [] + }, + /* Localization, for example "en", "de" etc. - see "_h5ai/conf/l10n" folder for possible values. Adjust it to your needs. If lang is not found