PageSourceSearch

https://politikenadvertorial.dk/static/js/compiledAdModule.js?d=f38a3a15

js politikenadvertorial.dk collected 2026-10-08 07:39:33 UTC 12,708 bytes, 286 lines download raw bytes

1"use strict";
2var polAdModuleHandler = (() => {
3    var __defProp = Object.defineProperty;
4    var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5    var __getOwnPropNames = Object.getOwnPropertyNames;
6    var __hasOwnProp = Object.prototype.hasOwnProperty;
7    var __export = (target, all) => {
8        for (var name in all)
9            __defProp(target, name, { get: all[name], enumerable: true });
10    };
11    var __copyProps = (to, from, except, desc) => {
12        if (from && typeof from === "object" || typeof from === "function") {
13            for (let key of __getOwnPropNames(from))
14                if (!__hasOwnProp.call(to, key) && key !== except)
15                    __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16        }
17        return to;
18    };
19    var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
21    // index.ts
22    var index_exports = {};
23    __export(index_exports, {
24        initAdModule: () => initAdModule,
25        setAndInitAdServerScripts: () => setAndInitAdServerScripts
26    });
27
28    
28// src/globals.ts
29    var globals = {
30        isDebug: false,
31        runtimeConfig: {},
32        googleTag: {},
33        livewrappedTag: {}
34    };
35
36    
36// src/util/log.ts
37    function setDebugModeLog(message, type) {
38        if (globals.isDebug) {
39            switch (type) {
40                case "error" /* error */:
41                    console.error(message);
42                    break;
43                case "warn" /* warn */:
44                    console.warn(message);
45                    break;
46                case "log" /* log */:
47                    console.log(message);
48                    break;
49                default:
50                    console.log(message);
51            }
52        }
53    }
54
55    
55// src/util/helpers.ts
56    var buildAdUnitCode = (fullConsent, placementCode, currentSection) => {
57        const sectionOrNoConsentValue = fullConsent ? currentSection?.toLowerCase() : "noconsent" /* NoConsentValue */;
58        const prefix = "pol";
59        return `${prefix}_${sectionOrNoConsentValue}_${placementCode.toLowerCase()}`;
60    };
61    var setTrackingPixelOnView = (adSlotDiv) => {
62        window.googletag.cmd.push(function() {
63            window.googletag.pubads().addEventListener("impressionViewable", function(event) {
64                const slot = event.slot;
65                if (slot.getSlotElementId() === adSlotDiv) {
66                    const adSlotId = slot.getSlotElementId();
67                    console.log("adSlotId: ", adSlotId);
68                    const sendMessageToIframe = (iframeElement) => {
69                        const messageToIframe = {
70                            "triggerPixel": true
71                        };
72                        iframeElement.contentWindow.postMessage(messageToIframe, "*");
73                    };
74                    const adFormats = {
75                        topscroll: "topscroll",
76                        megaboard: "megaboard",
77                        halfpage: "halfpage",
78                        monster: "monster",
79                        swedishtakeover_topscroll: "swedishtakeover_topscroll",
80                        swedishtakeover: "swedishtakeover"
81                    };
82                    const adFormat = Object.keys(adFormats).find((format) => adSlotId.includes(format));
83                    if (adFormat) {
84                        const iframeElem = document.querySelector(`iframe[id*=${adSlotId}]`);
85                        if (iframeElem) {
86                            console.log("sent message to iframe", adFormat);
87                            sendMessageToIframe(iframeElem);
88                        }
89                    } else {
90                        setDebugModeLog(`impressionViewable: Ad format not found: ${adSlotId}`, "error" /* error */);
91                    }
92                }
93            });
94        });
95    };
96    var setRootMarginBasedOnNetworkSpeed = (device) => {
97        const connection = window.navigator.connection;
98        if (connection && connection.effectiveType) {
99            switch (window.navigator.connection.effectiveType) {
100                case "slow-2g":
101                    return "1200px 0px 1200px 0px";
102                case "2g":
103                    return "600px 0px 600px 0px";
104                case "3g":
105                    return "300px 0px 300px 0px";
106                case "4g":
107                    return "100px 0px 100px 0px";
108                default:
109                    return "300px 0px 300px 0px";
110            }
111        } else if (device) {
112            switch (device) {
113                case "mobile":
114                    return "100px 0px 100px 0px";
115                case "desktop":
116                    return "300px 0px 300px 0px";
117                default:
118                    return "200px 0px 200px 0px";
119            }
120        } else {
121            return "300px 0px 300px 0px";
122        }
123    };
124    var buildCurrentSectionValue = (fullConsent, sectionName) => {
125        if (!fullConsent) {
126            return "noconsent" /* NoConsentValue */;
127        }
128        const uniqueSectionIdentifiers = ["viden", "rejser", "internationalt", "kultur", "job", "danmark", "ibyen", "fotografier", "forside", "debat", "mad", "sport", "klima", "annoncoerbetaltindhold", "edition", "hjerter"];
129        const providedSection = sectionName.toLowerCase();
130        const findMainSectionFromURL = location.pathname.split("/").filter(Boolean);
131        const checkMainSection = findMainSectionFromURL.length ? findMainSectionFromURL[0].toString().toLowerCase() : "forside";
132        if (uniqueSectionIdentifiers.includes(providedSection)) {
133            return providedSection;
134        } else if (uniqueSectionIdentifiers.indexOf(checkMainSection) === -1) {
135            return "ros" /* ROSValue */;
136        } else {
137            return checkMainSection;
138        }
139    };
140    var vetTargetingValues = (value) => {
141        if (value) {
142            return value.toString();
143        } else {
144            return "";
145        }
146    };
147    var checkUseDebugMode = () => {
148        return window.location.href.indexOf("/?google_console") > -1;
149    };
150    var getPathWithCommaSeparation = () => {
151        const urlPath = document.location.pathname;
152        if (urlPath) {
153            if (urlPath === "/") {
154                return "forside";
155            } else {
156                const segments = urlPath.split("/").filter(Boolean).join(",");
157                return segments;
158            }
159        } else {
160            return "";
161        }
162    };
163
164    
164// src/util/localStorage.ts
165    var localStorageErrorMsg = "LocalStorage is not existing...";
166    function setLocalStorageItem(key, value) {
167        if (window.localStorage) {
168            return window.localStorage.setItem(key, value);
169        } else console.warn(localStorageErrorMsg);
170    }
171    function getLocalStorageItem(key) {
172        if (window.localStorage) {
173            return window.localStorage.getItem(key);
174        } else console.warn(localStorageErrorMsg);
175    }
176
177    
177// src/util/tracking.ts
178    var getOrCreateLocalPPID = () => {
179        const PPIDKey = "pol_ppid";
180        if (getLocalStorageItem(PPIDKey)) {
181            return getLocalStorageItem(PPIDKey);
182        } else {
183            const newPPIDValue = window.crypto.randomUUID().toString();
184            setLocalStorageItem(PPIDKey, newPPIDValue);
185            return newPPIDValue;
186        }
187    };
188
189    // index.ts
190    function initAdModule(clientConfig) {
191        if (!clientConfig) {
192            setDebugModeLog("Client config was not provided to the initGptHandler function.", "error" /* error */);
193            return;
194        }
195        window.googletag = window.googletag || { cmd: [] };
196        var lwhb = window.lwhb || { cmd: [], disableAdServerScriptLoad: true };
197        const runtimeConfig = {
198            useDebugMode: checkUseDebugMode(),
199            networkCode: 83172459 /* NetworkCode */,
200            parentAdUnitCode: "politiken" /* ParentAdUnitCode */,
201            fullConsent: clientConfig.fullConsent ? clientConfig.fullConsent : false,
202            intersectionObserverRootMargin: setRootMarginBasedOnNetworkSpeed(clientConfig.deviceType),
203            deviceType: clientConfig.deviceType,
204            currentSection: clientConfig.currentSection,
205            targetingValues: clientConfig.targetingValues,
206            bannerData: clientConfig.bannerData
207        };
208        window.lwhb.cmd.push(function() {
209            window.lwhb.adServerKeywords({
210                "bloomreach_segment": vetTargetingValues(runtimeConfig.targetingValues.bloomreachSegment),
211                "activeFeatures": vetTargetingValues(runtimeConfig.targetingValues.activeFeatures),
212                "article": vetTargetingValues(runtimeConfig.targetingValues.articleId),
213                "isPremium": vetTargetingValues(runtimeConfig.targetingValues.isPremium),
214                "publisherName": vetTargetingValues(runtimeConfig.targetingValues.publisherName),
215                "politiken": vetTargetingValues(getPathWithCommaSeparation()),
216                "subscriptionFeatures": vetTargetingValues(runtimeConfig.targetingValues.subscriptionFeatures),
217                "suggested_tags": vetTargetingValues(runtimeConfig.targetingValues.suggestedTags),
218                "tags": vetTargetingValues(runtimeConfig.targetingValues.articleTags),
219                "articleTitle": vetTargetingValues(runtimeConfig.targetingValues.articleTitle),
220                "articleSubTitle": vetTargetingValues(runtimeConfig.targetingValues.articleSubTitle),
221                "articleAuthors": vetTargetingValues(runtimeConfig.targetingValues.articleAuthors),
222                "userType": vetTargetingValues(runtimeConfig.targetingValues.usertype),
223                "newsletters": vetTargetingValues(runtimeConfig.targetingValues.newsletters),
224                "internal_testing": "true"
225                // TODO: DELETE BEFORE MERGE
226            });
227        });
228        globals.isDebug = checkUseDebugMode();
229        globals.runtimeConfig = runtimeConfig;
230        globals.livewrappedTag = lwhb;
231        renderAd();
232    }
233    function renderAd() {
234        const runtimeConfig = globals.runtimeConfig;
235        const currentSection = buildCurrentSectionValue(runtimeConfig.fullConsent, runtimeConfig.currentSection);
236        runtimeConfig.bannerData.forEach((ad) => {
237            const { placementCode, adSize } = ad;
238            if (!placementCode || !adSize) {
239                setDebugModeLog(`"AD-DEBUG: Error finding placementcode: ${placementCode}`, "error" /* error */);
240                return;
241            }
242            const adUnitCode = buildAdUnitCode(runtimeConfig.fullConsent, placementCode, currentSection);
243            try {
244                window.lwhb.cmd.push(function() {
245                    window.lwhb.loadAd({
246                        tagId: placementCode,
247                        adUnitName: adUnitCode,
248                        userId: runtimeConfig.fullConsent ? getOrCreateLocalPPID() : "",
249                        sizes: adSize
250                    });
251                });
252                setTrackingPixelOnView(placementCode);
253            } catch (error) {
254                if (error instanceof Error) {
255                    setDebugModeLog(`AD-DEBUG: Error building ad slot. ${error.
255name}`, "error" /* error */);
256                }
257            }
258        });
259    }
260    async function setAndInitAdServerScripts() {
261        const adServers = [
262            "https://securepubads.g.doubleclick.net/tag/js/gpt.js" /* GptScriptCDN */,
263            "https://lwgadm.com/lw/pbjs?pid=5ee1f390-9f1d-45f2-83ed-e92f1051d9bf" /* LivewrappedCDN */
264        ];
265        const scriptPromises = adServers.map((adServerUrl) => {
266            return new Promise((resolve, reject) => {
267                const scriptElement = document.createElement("script");
268                scriptElement.async = true;
269                scriptElement.crossOrigin = "anonymous";
270                const headTag = document.querySelector("html > head");
271                if (!headTag) {
272                    console.log("ADMODULE: No head tag found....");
273                    reject(new Error("No head tag found"));
274                    return;
275                }
276                headTag.appendChild(scriptElement);
277                scriptElement.onload = () => resolve(scriptElement);
278                scriptElement.onerror = () => reject(new Error(`\u274C Failed to load script: ${scriptElement.src}`));
279                scriptElement.src = adServerUrl;
280            });
281        });
282        await Promise.all(scriptPromises);
283    }
284    return __toCommonJS(index_exports);
285})();
286window.polAdModuleHandler = polAdModuleHandler

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.