Repository URL to install this package:
|
Version:
2.1.0 ▾
|
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
var storage = require('../../helpers/storage.js');
// https://developers.google.com/analytics/devguides/collection/analyticsjs/cookie-usage#gtagjs_and_analyticsjs_universal_analytics_-_cookie_usage
// https://developers.google.com/analytics/devguides/collection/analyticsjs/cookie-usage#gajs_-_cookie_usage
var COOKIE_NAME_REGEXES = [/_ga/, /_gid/, /_gat/, /AMP_TOKEN/, /_dc_gtm_.*/, /_ga_.*/, /_gac_gb_.*/, /_gac_.*/, /__utma/, /__utmt/, /__utmb/, /__utmc/, /__utmz/, /__utmv/];
/**
* Initialises Google Analytics.
* @async
* @param {TrackingApiOptions} options - The API client's options
* @returns {Promise<boolean>}
*/
// eslint-disable-next-line no-unused-vars,require-await
var initGa = /*#__PURE__*/function () {
var _ref = _rollupPluginBabelHelpers.asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
window.dataLayer = window.dataLayer || [];
return _context.abrupt("return", true);
case 2:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function initGa() {
return _ref.apply(this, arguments);
};
}();
/**
* Removes Cookies associated with GA from the browser.
* @param {string|null} cookieDomain - Optionally, the cookie domain to use when removing cookies.
*/
var removeGaCookies = function removeGaCookies() {
var cookieDomain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
storage.removeCookies(COOKIE_NAME_REGEXES, cookieDomain);
};
/**
* Removes Google Analytics.
*
* @async
* @private
* @param {TrackingApiOptions} options - The API client's options
* @return {Promise.<boolean>}
*/
// eslint-disable-next-line require-await
var removeGa = /*#__PURE__*/function () {
var _ref2 = _rollupPluginBabelHelpers.asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(options) {
var _options$env, env;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_options$env = options.env, env = _options$env === void 0 ? {} : _options$env; // Reset GA
window.ga = undefined;
removeGaCookies(env.cookieDomain); // TODO: Check if there are additional opt-out measures that can be taken, eg: https://developers.google.com/analytics/devguides/collection/analyticsjs/user-opt-out
return _context2.abrupt("return", true);
case 4:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
return function removeGa(_x) {
return _ref2.apply(this, arguments);
};
}();
exports.initGa = initGa;
exports.removeGa = removeGa;
exports.removeGaCookies = removeGaCookies;
//# sourceMappingURL=init.js.map