Skip to content

Commit 199d1b3

Browse files
authored
✨[amp-ad smartadserver] Include consent data in iframe name (#39965)
* SADR-5675 include consent for GPT * SADR-5675 include consent for GPT update * SADR-5675 fixes for prettier and eslint
1 parent 810bc94 commit 199d1b3

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

extensions/amp-ad-network-smartadserver-impl/0.1/amp-ad-network-smartadserver-impl.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import {buildUrl} from '#ads/google/a4a/shared/url-builder';
1818

19+
import {intersectionEntryToJson} from '#core/dom/layout/intersection';
1920
import {getPageLayoutBoxBlocking} from '#core/dom/layout/page-layout-box';
2021
import {hasOwn} from '#core/types/object';
2122
import {tryParseJson} from '#core/types/object/json';
@@ -25,7 +26,11 @@ import {Services} from '#service';
2526
import {dev} from '#utils/log';
2627

2728
import {getOrCreateAdCid} from '../../../src/ad-cid';
28-
import {getConsentPolicyInfo} from '../../../src/consent';
29+
import {
30+
getConsentDataToForward,
31+
getConsentPolicyInfo,
32+
} from '../../../src/consent';
33+
import {getContextMetadata} from '../../../src/iframe-attributes';
2934
import {AmpA4A, XORIGIN_MODE} from '../../amp-a4a/0.1/amp-a4a';
3035

3136
/** @type {string} */
@@ -60,6 +65,29 @@ export class AmpAdNetworkSmartadserverImpl extends AmpA4A {
6065
this.addListener();
6166
}
6267

68+
/** @override */
69+
renderViaIframeGet_(adUrl) {
70+
this.maybeTriggerAnalyticsEvent_('renderCrossDomainStart');
71+
return getConsentDataToForward(this.element, this.getConsentPolicy()).then(
72+
(consentData) => {
73+
const contextMetadata = getContextMetadata(
74+
this.win,
75+
this.element,
76+
this.sentinel,
77+
{'consentSharedData': consentData}
78+
);
79+
80+
const intersection = this.element.getIntersectionChangeEntry();
81+
contextMetadata['_context']['initialIntersection'] =
82+
intersectionEntryToJson(intersection);
83+
return this.iframeRenderHelper_({
84+
'src': Services.xhrFor(this.win).getCorsUrl(this.win, adUrl),
85+
'name': JSON.stringify(contextMetadata),
86+
});
87+
}
88+
);
89+
}
90+
6391
/** @override */
6492
getAdUrl(opt_consentTuple, opt_rtcResponsesPromise) {
6593
return Promise.any([

extensions/amp-ad-network-smartadserver-impl/0.1/test/test-amp-ad-network-smartadserver-impl.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import {Services} from '#service';
2323

2424
import {createIframeWithMessageStub} from '#testing/iframe';
2525

26+
import * as consent from '../../../../src/consent';
27+
import * as iframe from '../../../../src/iframe-attributes';
2628
import {XORIGIN_MODE} from '../../../amp-a4a/0.1/amp-a4a';
2729
import {AmpAdNetworkSmartadserverImpl} from '../amp-ad-network-smartadserver-impl';
2830

@@ -173,6 +175,51 @@ describes.realWin('amp-ad-network-smartadserver-impl', realWinConfig, (env) => {
173175
});
174176
});
175177

178+
describe('renderViaIframeGet_', () => {
179+
let getContextMetadataStub;
180+
beforeEach(() => {
181+
getContextMetadataStub = env.sandbox
182+
.stub(iframe, 'getContextMetadata')
183+
.returns({
184+
_context: {},
185+
});
186+
env.sandbox
187+
.stub(consent, 'getConsentDataToForward')
188+
.resolves({consentString: 'constent', gdprApplies: true});
189+
element = createElementWithAttributes(doc, 'amp-ad', {
190+
width: '300',
191+
height: '250',
192+
type: 'smartadserver',
193+
});
194+
element.getIntersectionChangeEntry = () => ({
195+
rootBounds: {},
196+
intersectionRect: {},
197+
boundingClientRect: {},
198+
});
199+
impl = new AmpAdNetworkSmartadserverImpl(element);
200+
env.sandbox.stub(impl, 'iframeRenderHelper_');
201+
});
202+
afterEach(() => {
203+
env.sandbox.restore();
204+
});
205+
it('should call maybeTriggerAnalyticsEvent_', async () => {
206+
const spy = env.sandbox.spy(impl, 'maybeTriggerAnalyticsEvent_');
207+
expect(spy.called).to.be.false;
208+
impl.renderViaIframeGet_('fakeURL').then(() => {
209+
expect(spy.called).to.be.true;
210+
});
211+
});
212+
it('should call getContextMetadata with a consent data', async () => {
213+
expect(getContextMetadataStub.called).to.be.false;
214+
impl.renderViaIframeGet_('fakeURL').then(() => {
215+
expect(getContextMetadataStub.called).to.be.true;
216+
expect(getContextMetadataStub.getCall(0).args[3]).to.be.deep.equal({
217+
'consentSharedData': {consentString: 'constent', gdprApplies: true},
218+
});
219+
});
220+
});
221+
});
222+
176223
describe('getAdUrl', () => {
177224
it('should return proper url with vendor(default) data', async () => {
178225
element = createElementWithAttributes(doc, 'amp-ad', {

0 commit comments

Comments
 (0)