1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | }
|
9 | return function (d, b) {
|
10 | extendStatics(d, b);
|
11 | function __() { this.constructor = d; }
|
12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
13 | };
|
14 | })();
|
15 | var __values = (this && this.__values) || function (o) {
|
16 | var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
|
17 | if (m) return m.call(o);
|
18 | return {
|
19 | next: function () {
|
20 | if (o && i >= o.length) o = void 0;
|
21 | return { value: o && o[i++], done: !o };
|
22 | }
|
23 | };
|
24 | };
|
25 | var __read = (this && this.__read) || function (o, n) {
|
26 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
27 | if (!m) return o;
|
28 | var i = m.call(o), r, ar = [], e;
|
29 | try {
|
30 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
31 | }
|
32 | catch (error) { e = { error: error }; }
|
33 | finally {
|
34 | try {
|
35 | if (r && !r.done && (m = i["return"])) m.call(i);
|
36 | }
|
37 | finally { if (e) throw e.error; }
|
38 | }
|
39 | return ar;
|
40 | };
|
41 | var __spread = (this && this.__spread) || function () {
|
42 | for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
43 | return ar;
|
44 | };
|
45 | var __importStar = (this && this.__importStar) || function (mod) {
|
46 | if (mod && mod.__esModule) return mod;
|
47 | var result = {};
|
48 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
49 | result["default"] = mod;
|
50 | return result;
|
51 | };
|
52 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
53 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
54 | };
|
55 | Object.defineProperty(exports, "__esModule", { value: true });
|
56 | var React = __importStar(require("react"));
|
57 | var react_import_remote_1 = __importDefault(require("@shopify/react-import-remote"));
|
58 | var utilities_1 = require("./utilities");
|
59 | exports.SETUP_SCRIPT = "\n window['_gaq'] = window['_gaq'] || [];\n";
|
60 | function setupWithDebugScript(account) {
|
61 |
|
62 | return "window['ga-disable-GA_" + account + "'] = true;" + exports.SETUP_SCRIPT;
|
63 | }
|
64 | exports.setupWithDebugScript = setupWithDebugScript;
|
65 | exports.GA_JS_SCRIPT = 'https://stats.g.doubleclick.net/dc.js';
|
66 | var GaJSGoogleAnalytics = (function (_super) {
|
67 | __extends(GaJSGoogleAnalytics, _super);
|
68 | function GaJSGoogleAnalytics() {
|
69 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
70 | _this.setAnalytics = function (googleAnalytics) {
|
71 | var e_1, _a;
|
72 | 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;
|
73 | googleAnalytics.push(['_setAccount', account]);
|
74 | googleAnalytics.push(['_setDomainName', utilities_1.getRootDomain(domain)]);
|
75 | if (devId && devId.length > 0) {
|
76 | googleAnalytics.push(['_addDevId', devId]);
|
77 | }
|
78 | if (allowLinker !== undefined) {
|
79 | googleAnalytics.push(['_setAllowLinker', allowLinker]);
|
80 | }
|
81 | if (allowHash !== undefined) {
|
82 | googleAnalytics.push(['_setAllowHash', allowHash]);
|
83 | }
|
84 | try {
|
85 | for (var setVariables_1 = __values(setVariables), setVariables_1_1 = setVariables_1.next(); !setVariables_1_1.done; setVariables_1_1 = setVariables_1.next()) {
|
86 | var variable = setVariables_1_1.value;
|
87 | googleAnalytics.push(__spread(['_setCustomVar'], variable));
|
88 | }
|
89 | }
|
90 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
91 | finally {
|
92 | try {
|
93 | if (setVariables_1_1 && !setVariables_1_1.done && (_a = setVariables_1.return)) _a.call(setVariables_1);
|
94 | }
|
95 | finally { if (e_1) throw e_1.error; }
|
96 | }
|
97 | if (onLoad) {
|
98 | onLoad(googleAnalytics);
|
99 | }
|
100 | };
|
101 | return _this;
|
102 | }
|
103 | GaJSGoogleAnalytics.prototype.render = function () {
|
104 | var _a = this.props, account = _a.account, debug = _a.debug;
|
105 | return (React.createElement(React.Fragment, null,
|
106 | React.createElement("script", { id: "google-analytics-gtag-script", dangerouslySetInnerHTML: {
|
107 | __html: debug ? setupWithDebugScript(account) : exports.SETUP_SCRIPT,
|
108 | } }),
|
109 | React.createElement(react_import_remote_1.default, { preconnect: true, source: exports.GA_JS_SCRIPT, getImport: getLegacyAnalytics, onError: utilities_1.noop, onImported: this.setAnalytics })));
|
110 | };
|
111 | return GaJSGoogleAnalytics;
|
112 | }(React.PureComponent));
|
113 | exports.default = GaJSGoogleAnalytics;
|
114 | function getLegacyAnalytics(window) {
|
115 | return window._gaq;
|
116 | }
|