PageSourceSearch

https://www.eplus.com/scripts/gtm-martech.js

js eplus.com collected 2026-10-02 10:52:24 UTC 2,203 bytes, 71 lines download raw bytes

1import GtmMartech from '../plugins/gtm-martech/src/index.js';
2import { getOneTrustConsentCallback } from './oneTrust.js';
3import { ANALYTICS_CONFIG, loadConfigParams, isMartechDisabled } from './configs.js';
4
5/**
6 * Resolves the GA4 measurement ID.
7 * Prefers the value from the server config, falls back to the hardcoded default.
8 * @param {Object} serverVals Key/value pairs fetched from /global-config.json
9 * @returns {string} GA4 measurement ID
10 */
11function getGa4ID(serverVals) {
12    return serverVals.ga4Id ?? ANALYTICS_CONFIG.ga4Id;
13}
14
15/**
16 * Resolves the GTM container ID.
17 * Prefers the value from the server config, falls back to the hardcoded default.
18 * @param {Object} serverVals Key/value pairs fetched from /global-config.json
19 * @returns {string} GTM container ID
20 */
21function getGtmID(serverVals) {
22    return serverVals.gtmId ?? ANALYTICS_CONFIG.gtmId;
23}
24
25/**
26 * Lazy-initialised martech wrapper.
27 * Resolves GA4/GTM IDs on first eager() call so there is no top-level await
28 * and the module can be statically imported without parse issues.
29 */
30class MartechWrapper {
31    constructor() {
32        this._instance = null;
33        this._initPromise = null;
34    }
35
36    async _init() {
37        if (this._initPromise) return this._initPromise;
38        this._initPromise = (async () => {
39            const disabled = isMartechDisabled();
40            const serverVals = await loadConfigParams();
41            const ga4Id = getGa4ID(serverVals);
42            const gtmId = getGtmID(serverVals);
43
44            this._instance = new GtmMartech({
45                analytics: !disabled,
46                tags: [ga4Id],
47                containers: {
48                    lazy: [gtmId],
49                    delayed: [],
50                },
51                gtagConfig: {},
52                consent: !disabled,
53                consentCallback: getOneTrustConsentCallback(),
54            });
55            return this._instance;
56        })();
57        return this._initPromise;
58    }
59
60    async eager() {
61        const inst = await this._init();
62        return inst.eager();
63    }
64
65    async lazy() {
66        const inst = await this._init();
67        return inst.lazy();
68    }
69}
70
71export default new MartechWrapper();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.