|
| 1 | +import {loadScript, validateData} from '#3p/3p'; |
| 2 | + |
| 3 | +import {CONSENT_STRING_TYPE} from '#core/constants/consent-state'; |
| 4 | + |
| 5 | +/** |
| 6 | + * @param {!Window} global |
| 7 | + * @param {!Object} data |
| 8 | + */ |
| 9 | +export function impactify(global, data) { |
| 10 | + validateData(data, ['appId', 'format', 'style']); |
| 11 | + |
| 12 | + const doc = global.document; |
| 13 | + const container = doc.createElement('div'); |
| 14 | + const slotId = `impactify-slot-${Math.floor(Math.random() * 10000)}`; |
| 15 | + container.id = slotId; |
| 16 | + doc.getElementById('c').appendChild(container); |
| 17 | + |
| 18 | + // GDPR and consent handling |
| 19 | + const { |
| 20 | + initialConsentMetadata, |
| 21 | + initialConsentValue, |
| 22 | + noContentAvailable, |
| 23 | + renderStart, |
| 24 | + } = global.context; |
| 25 | + |
| 26 | + const gdprApplies = initialConsentMetadata?.gdprApplies; |
| 27 | + const gdprConsent = |
| 28 | + initialConsentMetadata?.consentStringType === CONSENT_STRING_TYPE.TCF_V2 |
| 29 | + ? initialConsentValue |
| 30 | + : ''; |
| 31 | + |
| 32 | + global.impactifyTag = global.impactifyTag || []; |
| 33 | + global.impactifyTag.push({ |
| 34 | + appId: data['appId'], |
| 35 | + format: data['format'], |
| 36 | + style: data['style'], |
| 37 | + 'gdpr_consent': gdprConsent, |
| 38 | + gdpr: gdprApplies, |
| 39 | + slotId, |
| 40 | + isAmp: true, |
| 41 | + codeName: `${data['width']}x${data['height']}`, |
| 42 | + onAd: () => renderStart(), |
| 43 | + onNoAd: () => noContentAvailable(), |
| 44 | + }); |
| 45 | + |
| 46 | + loadScript(global, 'https://ad.impactify.io/static/ad/tag.js'); |
| 47 | +} |
0 commit comments