Skip to content

Commit 045b685

Browse files
authored
🧪 Introduce structure for attribution-reporting client side experiment (ampproject#38620)
* introduce exp * rename branches * dep check * fix tests
1 parent 2908094 commit 045b685

File tree

9 files changed

+80
-24
lines changed

9 files changed

+80
-24
lines changed

Diff for: ‎build-system/test-configs/dep-check-config.js

+4
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ exports.rules = [
155155
'extensions/amp-ad-network-adsense-impl/0.1/amp-ad-network-adsense-impl.js->extensions/amp-a4a/0.1/signature-verifier.js',
156156
'extensions/amp-ad-network-doubleclick-impl/0.1/amp-ad-network-doubleclick-impl.js->extensions/amp-a4a/0.1/signature-verifier.js',
157157

158+
// A4A impls using attribution-reporting API
159+
'extensions/amp-ad-network-adsense-impl/0.1/amp-ad-network-adsense-impl.js->extensions/amp-a4a/0.1/privacy-sandbox-utils.js',
160+
'extensions/amp-ad-network-doubleclick-impl/0.1/amp-ad-network-doubleclick-impl.js->extensions/amp-a4a/0.1/privacy-sandbox-utils.js',
161+
158162
// And a few more things depend on a4a.
159163
'extensions/amp-ad-custom/0.1/amp-ad-custom.js->extensions/amp-a4a/0.1/amp-ad-network-base.js',
160164
'extensions/amp-ad-custom/0.1/amp-ad-custom.js->extensions/amp-a4a/0.1/amp-ad-type-defs.js',

Diff for: ‎extensions/amp-a4a/0.1/amp-a4a.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ import {dev, devAssert, logHashParam, user, userAssert} from '#utils/log';
3232
import {A4AVariableSource} from './a4a-variable-source';
3333
import {getExtensionsFromMetadata} from './amp-ad-utils';
3434
import {processHead} from './head-validation';
35-
import {
36-
createSecureDocSkeleton,
37-
createSecureFrame,
38-
isAttributionReportingSupported,
39-
} from './secure-frame';
35+
import {isAttributionReportingAllowed} from './privacy-sandbox-utils';
36+
import {createSecureDocSkeleton, createSecureFrame} from './secure-frame';
4037
import {SignatureVerifier, VerificationStatus} from './signature-verifier';
4138
import {whenWithinViewport} from './within-viewport';
4239

@@ -2037,7 +2034,7 @@ export class AmpA4A extends AMP.BaseElement {
20372034
// request completes.
20382035
let featurePolicies = "sync-xhr 'none';";
20392036

2040-
if (isAttributionReportingSupported(this.win.document)) {
2037+
if (isAttributionReportingAllowed(this.win.document)) {
20412038
featurePolicies += "attribution-reporting 'src';";
20422039
}
20432040

Diff for: ‎extensions/amp-a4a/0.1/privacy-sandbox-utils.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Determine if `attribution-reporting` API is available in browser.
3+
* @param {!Document} doc
4+
* @return {boolean}
5+
*/
6+
export function isAttributionReportingAvailable(doc) {
7+
return doc.featurePolicy?.features().includes('attribution-reporting');
8+
}
9+
10+
/**
11+
* Determine if `attribution-reporting` API is allowed in current context.
12+
* @param {!Document} doc
13+
* @return {boolean}
14+
*/
15+
export function isAttributionReportingAllowed(doc) {
16+
return doc.featurePolicy?.allowedFeatures().includes('attribution-reporting');
17+
}

Diff for: ‎extensions/amp-a4a/0.1/secure-frame.js

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {createElementWithAttributes, escapeHtml} from '#core/dom';
22

3+
import {isAttributionReportingAllowed} from './privacy-sandbox-utils';
4+
35
import {getFieSafeScriptSrcs} from '../../../src/friendly-iframe-embed';
46

57
// If making changes also change ALLOWED_FONT_REGEX in head-validation.js
@@ -87,18 +89,9 @@ export function createSecureFrame(win, title, height, width) {
8789
})
8890
);
8991

90-
if (isAttributionReportingSupported(document)) {
92+
if (isAttributionReportingAllowed(document)) {
9193
iframe.setAttribute('allow', `attribution-reporting 'src'`);
9294
}
9395

9496
return iframe;
9597
}
96-
97-
/**
98-
* Determine if `attribution-reporting` API is available in browser.
99-
* @param {!Document} doc
100-
* @return {boolean}
101-
*/
102-
export function isAttributionReportingSupported(doc) {
103-
return doc.featurePolicy?.features().includes('attribution-reporting');
104-
}

Diff for: ‎extensions/amp-a4a/0.1/test/test-amp-a4a.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import {
5050
assignAdUrlToError,
5151
protectFunctionWrapper,
5252
} from '../amp-a4a';
53-
import * as secureFrame from '../secure-frame';
53+
import * as privacySandboxUtils from '../privacy-sandbox-utils';
5454
import {AMP_SIGNATURE_HEADER, VerificationStatus} from '../signature-verifier';
5555

5656
describes.realWin('amp-a4a: no signing', {amp: true}, (env) => {
@@ -923,7 +923,7 @@ describes.realWin('amp-a4a', {amp: true}, (env) => {
923923

924924
it('should set feature policy for attribution-reporting when supported', async () => {
925925
env.sandbox
926-
.stub(secureFrame, 'isAttributionReportingSupported')
926+
.stub(privacySandboxUtils, 'isAttributionReportingAllowed')
927927
.returns(true);
928928
a4a.sandboxHTMLCreativeFrame = () => true;
929929
a4a.onLayoutMeasure();
@@ -936,7 +936,7 @@ describes.realWin('amp-a4a', {amp: true}, (env) => {
936936

937937
it('should not set feature policy for attribution-reporting when not supported', async () => {
938938
env.sandbox
939-
.stub(secureFrame, 'isAttributionReportingSupported')
939+
.stub(privacySandboxUtils, 'isAttributionReportingAllowed')
940940
.returns(false);
941941
a4a.sandboxHTMLCreativeFrame = () => true;
942942
a4a.onLayoutMeasure();
@@ -1035,7 +1035,7 @@ describes.realWin('amp-a4a', {amp: true}, (env) => {
10351035

10361036
it('should set feature policy for attribution-reporting when supported', async () => {
10371037
env.sandbox
1038-
.stub(secureFrame, 'isAttributionReportingSupported')
1038+
.stub(privacySandboxUtils, 'isAttributionReportingAllowed')
10391039
.returns(true);
10401040
a4a.sandboxHTMLCreativeFrame = () => false;
10411041
a4a.onLayoutMeasure();
@@ -1048,7 +1048,7 @@ describes.realWin('amp-a4a', {amp: true}, (env) => {
10481048

10491049
it('should not set feature policy for attribution-reporting when not supported', async () => {
10501050
env.sandbox
1051-
.stub(secureFrame, 'isAttributionReportingSupported')
1051+
.stub(privacySandboxUtils, 'isAttributionReportingAllowed')
10521052
.returns(false);
10531053
a4a.sandboxHTMLCreativeFrame = () => false;
10541054
a4a.onLayoutMeasure();
@@ -1169,7 +1169,7 @@ describes.realWin('amp-a4a', {amp: true}, (env) => {
11691169

11701170
it('should set feature policy for attribution-reporting when supported', async () => {
11711171
env.sandbox
1172-
.stub(secureFrame, 'isAttributionReportingSupported')
1172+
.stub(privacySandboxUtils, 'isAttributionReportingAllowed')
11731173
.returns(true);
11741174
a4a.sandboxHTMLCreativeFrame = () => false;
11751175
a4a.onLayoutMeasure();
@@ -1186,7 +1186,7 @@ describes.realWin('amp-a4a', {amp: true}, (env) => {
11861186

11871187
it('should not set feature policy for attribution-reporting when not supported', async () => {
11881188
env.sandbox
1189-
.stub(secureFrame, 'isAttributionReportingSupported')
1189+
.stub(privacySandboxUtils, 'isAttributionReportingAllowed')
11901190
.returns(false);
11911191
a4a.sandboxHTMLCreativeFrame = () => false;
11921192
a4a.onLayoutMeasure();

Diff for: ‎extensions/amp-ad-network-adsense-impl/0.1/amp-ad-network-adsense-impl.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
getExperimentBranch,
4343
randomlySelectUnsetExperiments,
4444
} from '#experiments';
45+
import {AttributionReporting} from '#experiments/attribution-reporting';
4546
import {StoryAdPlacements} from '#experiments/story-ad-placements';
4647
import {StoryAdSegmentExp} from '#experiments/story-ad-progress-segment';
4748

@@ -51,6 +52,8 @@ import {Navigation} from '#service/navigation';
5152
import {getData} from '#utils/event-helper';
5253
import {dev, devAssert, user} from '#utils/log';
5354

55+
import {isAttributionReportingAllowed} from 'extensions/amp-a4a/0.1/privacy-sandbox-utils';
56+
5457
import {AdsenseSharedState} from './adsense-shared-state';
5558
import {ResponsiveState} from './responsive-state';
5659

@@ -223,7 +226,19 @@ export class AmpAdNetworkAdsenseImpl extends AmpA4A {
223226
*/
224227
divertExperiments() {
225228
const experimentInfoList =
226-
/** @type {!Array<!../../../src/experiments.ExperimentInfo>} */ ([]);
229+
/** @type {!Array<!../../../src/experiments.ExperimentInfo>} */ ([
230+
{
231+
experimentId: AttributionReporting.ID,
232+
isTrafficEligible: () =>
233+
isAttributionReportingAllowed(this.win.document),
234+
branches: [
235+
AttributionReporting.ENABLE,
236+
AttributionReporting.DISABLE,
237+
AttributionReporting.ENABLE_NO_ASYNC,
238+
AttributionReporting.DISABLE_NO_ASYNC,
239+
],
240+
},
241+
]);
227242
const setExps = randomlySelectUnsetExperiments(
228243
this.win,
229244
experimentInfoList

Diff for: ‎extensions/amp-ad-network-doubleclick-impl/0.1/amp-ad-network-doubleclick-impl.js

+14
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import {
6767
isExperimentOn,
6868
randomlySelectUnsetExperiments,
6969
} from '#experiments';
70+
import {AttributionReporting} from '#experiments/attribution-reporting';
7071
import {StoryAdPlacements} from '#experiments/story-ad-placements';
7172
import {StoryAdSegmentExp} from '#experiments/story-ad-progress-segment';
7273

@@ -76,6 +77,8 @@ import {RTC_VENDORS} from '#service/real-time-config/callout-vendors';
7677

7778
import {dev, devAssert, user} from '#utils/log';
7879

80+
import {isAttributionReportingAllowed} from 'extensions/amp-a4a/0.1/privacy-sandbox-utils';
81+
7982
import {
8083
FlexibleAdSlotDataTypeDef,
8184
getFlexibleAdSlotData,
@@ -475,6 +478,17 @@ export class AmpAdNetworkDoubleclickImpl extends AmpA4A {
475478
},
476479
branches: Object.values(IDLE_CWV_EXP_BRANCHES),
477480
},
481+
{
482+
experimentId: AttributionReporting.ID,
483+
isTrafficEligible: () =>
484+
isAttributionReportingAllowed(this.win.document),
485+
branches: [
486+
AttributionReporting.ENABLE,
487+
AttributionReporting.DISABLE,
488+
AttributionReporting.ENABLE_NO_ASYNC,
489+
AttributionReporting.DISABLE_NO_ASYNC,
490+
],
491+
},
478492
]);
479493
const setExps = this.randomlySelectUnsetExperiments_(experimentInfoList);
480494
Object.keys(setExps).forEach(

Diff for: ‎src/experiments/attribution-reporting.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @const
3+
* @type {Object<string, string>}
4+
*/
5+
export const AttributionReporting = {
6+
ID: 'attribution-reporting',
7+
DISABLE: '44776500',
8+
ENABLE: '44776501',
9+
DISABLE_NO_ASYNC: '44776502',
10+
ENABLE_NO_ASYNC: '44776503',
11+
};

Diff for: ‎tools/experiments/experiments-config.js

+5
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,9 @@ export const EXPERIMENTS = [
193193
name: 'Enable paywall experiences in web stories by turning on amp-story-subscriptions extension',
194194
spec: 'https://github.com/ampproject/amphtml/pull/38179',
195195
},
196+
{
197+
id: 'attribution-reporting',
198+
name: 'Enable new privacy preserving attribution reporting APIs',
199+
spec: 'https://github.com/ampproject/amphtml/pull/35347',
200+
},
196201
];

0 commit comments

Comments
 (0)