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

Implement getCustomRealTimeConfigMacros for Doubleclick Fast Fetch #12539

Merged
merged 10 commits into from Jan 3, 2018

Conversation

bradfrizzell
Copy link
Contributor

See #12374

@@ -17,11 +17,18 @@
<body>
<h2> NOTE: Must disable check that isSecureUrl for testing </h2>
<h2>Doubleclick with RTC</h2>
<amp-ad width="320" height="50"
<!--<amp-ad width="320" height="50"
Copy link
Contributor

Choose a reason for hiding this comment

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

remove commented out slot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -100,6 +100,7 @@ import {
import {
addExperimentIdToElement,
} from '../../../ads/google/a4a/traffic-experiments';
import {getAdCid} from '../../../src/ad-cid';
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see you using this yet. Presumably you'll remove and handle in second PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

getCustomRealTimeConfigMacros_() {
const macros = {};
const docInfo = Services.documentInfoForDoc(this.element);
macros['PAGEVIEWID'] = docInfo.pageViewId;
Copy link
Contributor

Choose a reason for hiding this comment

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

const docInfo = ..
return {
'HREF': this.win.location.href,
'DATASLOT': ...
};

Also I would have expected these to be function values such that they are only evaluated if/when the macro exists. In fact, you could make it so that the element is passed to the function thereby allowing this to be a static object. Seems much more efficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to function values

() => this.element.getAttribute('data-multi-size-validation'),
OVERRIDEWIDTH: () => this.element.getAttribute('data-override-width'),
OVERRIDEHEIGHT: () => this.element.getAttribute('data-override-height'),
JSON: () => this.element.getAttribute('data-json'),
Copy link
Contributor

Choose a reason for hiding this comment

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

This could greatly increase the length of the url. Do we truncate the url if its too long? Do we indicate it was truncated? Is there only a portion of the JSON that they want?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added truncation to 16k

/** @override */
getCustomRealTimeConfigMacros_() {
return {
PAGEVIEWID: () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: () => Services.documentInfoForDoc(this.element).pageViewId,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return docInfo.pageViewId;
},
HREF: () => this.win.location.href,
DATASLOT: () => this.element.getAttribute('data-slot'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider whitelist of allowed attributes and then single macro with parameter of name of attribute to be extracted:

const whitelist = {};
ATTR = name => !!whitelist[name] && this.element.getAttribute(name)

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 doesn't work with how the url replacements works. It needs a full list of all valid macros to look for in the URL. This suggestion would only work if we know what the valid macros are already, and then go from there.

@@ -715,6 +715,25 @@ export class AmpAdNetworkDoubleclickImpl extends AmpA4A {
return {'artc': artc.join() || null, 'ati': ati.join(), 'ard': ard.join()};
}

/** @override */
getCustomRealTimeConfigMacros_() {
const whitelist = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add documentation about why this exists (e.g. To make attributes accessible, add here...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return {
PAGEVIEWID: () => Services.documentInfoForDoc(this.element).pageViewId,
HREF: () => this.win.location.href,
ATTR: name => !!whitelist[name] && this.element.getAttribute(name),
Copy link
Contributor

Choose a reason for hiding this comment

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

You could be a bit fancier and dev or user warn on attempted access to missing attribute. Also, do you know if element names are case sensitive? Perhaps this should be insensitive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -157,6 +160,10 @@ function inflateAndSendRtc_(a4aElement, url, seenUrls, promiseArray,
opt_vendor || url);
}
seenUrls[url] = true;
if (url.length > MAX_URL_LENGTH) {
url = url.substr(0, MAX_URL_LENGTH - 12).replace(/%\w?$/, '');
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I would make this all one line

height: macros['height'],
type: 'doubleclick',
layout: 'fixed',
'data-slot': macros['data-slot'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Verify case insensitivity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, added some crazazy cases

@@ -271,4 +272,40 @@ describes.realWin('DoubleClick Fast Fetch RTC', {amp: true}, env => {
.to.deep.equal(response);
});
});

describe('getCustomRealTimeConfigMacros', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test coverage for truncation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, broke out to separate function for easiness of testing

Copy link
Contributor

@keithwrightbos keithwrightbos left a comment

Choose a reason for hiding this comment

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

Assuming remaining items will be addressed.

@erwinmombay erwinmombay merged commit 50e3e0c into master Jan 3, 2018
gzgogo pushed a commit to gzgogo/amphtml that referenced this pull request Jan 26, 2018
…mpproject#12539)

* Start work on macros

* Add test coverage

* Responding to feedback

* Responded to feedback

* Respond to feedback

* Fix test

* Change url replacement to be cleaner

* Respond to feedback

* feedback

* Respond
@bradfrizzell bradfrizzell deleted the frizz-macros branch April 12, 2018 14:31
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.

None yet

5 participants