PageSourceSearch

https://static.debragga.com/version1790253851/frontend/Creatingdig…/Dotdigitalgroup_Email/js/dotdigital-tag.js

js debragga.com collected 2026-09-26 09:16:35 UTC 3,523 bytes, 111 lines download raw bytes

1/**
2 * Dotdigital tracking proxy for Magento
3 * Queues method calls until the real Dotdigital script loads
4 *
5 * @fileoverview Provides a proxy interface for Dotdigital tracking that queues
6 * method calls until the external Dotdigital script is loaded and ready.
7 * @author Dotdigitalgroup
8 * @version 1.0.0
9 */
10const queuedMethodCalls = [];
11
12/**
13 * Initialize Dotdigital tracking and load the external script
14 *
15 * @param {string} regionPrefix - Dotdigital region identifier (e.g., 'r1', 'r2', 'r3')
16 * @param {string} profileId - Dotdigital profile/account identifier
17 * @returns {void}
18 */
19const initializeDotdigital = (regionPrefix, profileId) => {
20    if (!regionPrefix || !profileId) {
21        console.warn('Dotdigital initialization failed: regionId and profileId are required');
22        return;
23    }
24
25    if (document.querySelector(`script[src*="${profileId}/ddgtag.js"]`)) {
26        triggerReadyEvent();
27        return;
28    }
29
30    const script = document.createElement('script');
31    script.src = `//${regionPrefix}.ddlnk.net/${profileId}/ddgtag.js`;
32    script.async = true;
33    script.onerror = () => console.error('Failed to load Dotdigital script');
34    document.head.appendChild(script);
35};
36
37/**
38 * Mark Dotdigital as ready and process all queued method calls
39 *
40 * @returns {void}
41 */
42const triggerReadyEvent = () => {
43    if ('isProxy' in window.ddg) return;
44    window.dispatchEvent(new CustomEvent('DotdigitalTagLoaded', { detail: { timestamp: Date.now() } }));
45    processQueuedMethodCalls();
46};
47
48/**
49 * Execute all queued method calls using the current Dotdigital object
50 *
51 * @returns {void}
52 */
53const processQueuedMethodCalls = () => {
54    while (queuedMethodCalls.length > 0) {
55        const { methodName, methodArguments, promiseResolve } = queuedMethodCalls.shift();
56        if (window.ddg && typeof window.ddg[methodName] === 'function') {
57            try {
58                const result = window.ddg[methodName](...methodArguments);
59                promiseResolve?.(result);
60            } catch (error) {
61                console.error(`Error calling Dotdigital ${methodName}:`, error);
62                promiseResolve?.(false);
63            }
64        } else {
65            console.log(`Dotdigital ${methodName}:`, methodArguments);
66            promiseResolve?.(true);
67        }
68    }
69};
70
71/**
72 * Create a proxy object that intercepts and queues Dotdigital method calls
73 *
74 * @returns {Proxy} The proxy object for Dotdigital tracking
75 */
76const createDotdigitalProxy = () => new Proxy(
77    { init: initializeDotdigital, isProxy: true },
78    {
79    /**
80     * Proxy getter that intercepts method calls
81     *
82     * @param {Object} target - The target object
83     * @param {string} methodName - The method name being accessed
84     * @returns {Function} The intercepted method or queuing function
85     */
86    get(target, methodName) {
87        if (methodName in target) {
88            return target[methodName];
89        }
90        return (...args) => {
91            return new Promise(resolve => {
92                queuedMethodCalls.push({
93                    methodName,
94                    methodArguments: args,
95                    promiseResolve: resolve
96                });
97            });
98        };
99    }
100});
101
102/**
103 * Override window.ddg setter to detect object replacement
104 */
105Object.defineProperty(window, 'ddg', {
106    get: () => window._ddgCurrent,
107    set: (value)  => (window._ddgCurrent = value, triggerReadyEvent())
108});
109
110// Initialize with our proxy
111window._ddgCurrent = createDotdigitalProxy();

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.