Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support variable expansion in amp-consent #28700

Merged
merged 3 commits into from
Jun 12, 2020
Merged

Conversation

zhouyx
Copy link
Contributor

@zhouyx zhouyx commented Jun 4, 2020

Closes #28588

export function getConsentCID(node) {
return Services.cidForDoc(node).then((cid) => {
return cid.get(
{scope: CID_SCOPE, createCookieIfNotPresent: true},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I fixed the scope of the CLIENT_ID API. Because I don't want the CMP to be able set any scope value to get the tracking id (_ga for example).
The CLIENT_ID here is more like a USER_CONSENT_ID. All CMPs will share the same CID. (In the case where the publisher switch to a different CMP provider).

I could switch to a different variable name given I'm not using the exact CLIENT_ID API to be more specific. (e.g USER_ID). Let me know if you prefer that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think either a comment explaining this distinction or the changing to USER_ID would be sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decided to leave as it is

Copy link
Member

@danielrozenberg danielrozenberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval for presubmit-checks.js

export function getConsentCID(node) {
return Services.cidForDoc(node).then((cid) => {
return cid.get(
{scope: CID_SCOPE, createCookieIfNotPresent: true},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think either a comment explaining this distinction or the changing to USER_ID would be sufficient.

/** @type {string} */ (this.onUpdateHref_),
init
);
expandConsentEndpointUrl(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will getConsentId(this.ampdoc_) return a different USER_ID than getConsentId(this.ampdoc_.getBody())?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.ampdoc_.getHeadNode() is actually a better method, because the getBody() may not be ready in the case of shadowRoot.

No it should always return the same value. The only reason I need to pass an element here is urlReplacementsForDoc() only takes in element. This is because FIE shares the same ampdoc as the parent doc before the ampdoc-fie experiment is shipped. And we need to use the element to determine if the request is from within the FIE or the ampdoc.
Note <amp-consent> is not supported in FIE, so no need to worry about that.

Comment on lines +62 to +67
it('read cmp config', async () => {
appendConfigScriptElement(doc, element, dict({}));
element.setAttribute('type', '_ping_');
const consentConfig = new ConsentConfig(element);
return expect(
consentConfig.getConsentConfigPromise()
).to.eventually.deep.equal(
// Make a deep copy of the config to avoid error when deleting fields
const config = JSON.parse(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, it would be great if would could fake the ping cmp here, so that we don't have to alter cmps.js.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually the other way around. I intended to change the fake setting in cmps.js. For manual testing reason, and also to serve as an example to other CMPS. I changed the unit test here only to fix it.

@@ -205,7 +205,7 @@ export class Services {
}

/**
* @param {!Element|!./service/ampdoc-impl.AmpDoc} elementOrAmpDoc
* @param {!Element|!ShadowRoot|!./service/ampdoc-impl.AmpDoc} elementOrAmpDoc
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jridgewell for approval

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can shadowRoots have different CIDs? If so, this is broken, since it'll get the shared ampdoc for the page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shadowRoot gets the same CID. We haven't get request to create new CID for shadowRoot, afaik content in the shadowRoot are from the same domain thus should get the same id.

I added this to fix type check. Shouldn't affect behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jridgewell Does the sound good to you?

@zhouyx zhouyx requested a review from jridgewell June 8, 2020 23:46
Copy link
Contributor

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving src/services.js change.

@zhouyx zhouyx merged commit e057384 into ampproject:master Jun 12, 2020
@zhouyx zhouyx deleted the var-sub branch June 12, 2020 21:17
mszylkowski pushed a commit to mszylkowski/amphtml that referenced this pull request Jun 17, 2020
* support variable expansion in amp-consent

* switch to head

* type check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow variable substitution in amp-consent
6 participants