1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var React = tslib_1.__importStar(require("react"));
|
5 | var react_import_remote_1 = tslib_1.__importDefault(require("@shopify/react-import-remote"));
|
6 | var utilities_1 = require("./utilities");
|
7 | exports.SETUP_SCRIPT = "\n window['_gaq'] = window['_gaq'] || [];\n";
|
8 | function setupWithDebugScript(account) {
|
9 |
|
10 | return "window['ga-disable-" + account + "'] = true;" + exports.SETUP_SCRIPT;
|
11 | }
|
12 | exports.setupWithDebugScript = setupWithDebugScript;
|
13 | exports.GA_JS_SCRIPT = 'https://stats.g.doubleclick.net/dc.js';
|
14 | var GaJSGoogleAnalytics = (function (_super) {
|
15 | tslib_1.__extends(GaJSGoogleAnalytics, _super);
|
16 | function GaJSGoogleAnalytics() {
|
17 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
18 | _this.setAnalytics = function (googleAnalytics) {
|
19 | var e_1, _a;
|
20 | var _b = _this.props, account = _b.account, domain = _b.domain, devId = _b.devId, allowLinker = _b.allowLinker, allowHash = _b.allowHash, _c = _b.set, setVariables = _c === void 0 ? [] : _c, onLoad = _b.onLoad;
|
21 | googleAnalytics.push(['_setAccount', account]);
|
22 | googleAnalytics.push(['_setDomainName', utilities_1.getRootDomain(domain)]);
|
23 | if (devId && devId.length > 0) {
|
24 | googleAnalytics.push(['_addDevId', devId]);
|
25 | }
|
26 | if (allowLinker !== undefined) {
|
27 | googleAnalytics.push(['_setAllowLinker', allowLinker]);
|
28 | }
|
29 | if (allowHash !== undefined) {
|
30 | googleAnalytics.push(['_setAllowHash', allowHash]);
|
31 | }
|
32 | try {
|
33 | for (var setVariables_1 = tslib_1.__values(setVariables), setVariables_1_1 = setVariables_1.next(); !setVariables_1_1.done; setVariables_1_1 = setVariables_1.next()) {
|
34 | var variable = setVariables_1_1.value;
|
35 | googleAnalytics.push(tslib_1.__spread(['_setCustomVar'], variable));
|
36 | }
|
37 | }
|
38 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
39 | finally {
|
40 | try {
|
41 | if (setVariables_1_1 && !setVariables_1_1.done && (_a = setVariables_1.return)) _a.call(setVariables_1);
|
42 | }
|
43 | finally { if (e_1) throw e_1.error; }
|
44 | }
|
45 | if (onLoad) {
|
46 | onLoad(googleAnalytics);
|
47 | }
|
48 | };
|
49 | return _this;
|
50 | }
|
51 | GaJSGoogleAnalytics.prototype.render = function () {
|
52 | var _a = this.props, account = _a.account, disableTracking = _a.disableTracking, nonce = _a.nonce;
|
53 | return (React.createElement(React.Fragment, null,
|
54 | React.createElement("script", { id: "google-analytics-gtag-script", dangerouslySetInnerHTML: {
|
55 | __html: disableTracking
|
56 | ? setupWithDebugScript(account)
|
57 | : exports.SETUP_SCRIPT,
|
58 | }, nonce: nonce }),
|
59 | React.createElement(react_import_remote_1.default, { preconnect: true, source: exports.GA_JS_SCRIPT, nonce: nonce, getImport: getLegacyAnalytics, onError: utilities_1.noop, onImported: this.setAnalytics })));
|
60 | };
|
61 | return GaJSGoogleAnalytics;
|
62 | }(React.PureComponent));
|
63 | exports.default = GaJSGoogleAnalytics;
|
64 | function getLegacyAnalytics(window) {
|
65 | return window._gaq;
|
66 | }
|