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
Conversation
9160c3d
to
79e2cd9
Compare
examples/doubleclick-rtc.amp.html
Outdated
@@ -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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commented out slot?
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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: () => { |
There was a problem hiding this comment.
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,
There was a problem hiding this comment.
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'), |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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...)
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?$/, ''); |
There was a problem hiding this comment.
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'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verify case insensitivity
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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.
…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
See #12374