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

Story-Auto-Ads Skeleton #13239

Merged
merged 6 commits into from
Feb 5, 2018
Merged

Story-Auto-Ads Skeleton #13239

merged 6 commits into from
Feb 5, 2018

Conversation

calebcordry
Copy link
Member

This is the start of the implementation of a new amp-story-auto-ads component that will handle the scheduling and display of ads in an amp-story.

@calebcordry
Copy link
Member Author

@lannka Is there anything else you want in this initial PR?

gulpfile.js Outdated
@@ -135,6 +135,7 @@ declareExtension('amp-soundcloud', '0.1', {hasCss: false});
declareExtension('amp-springboard-player', '0.1', {hasCss: false});
declareExtension('amp-sticky-ad', '1.0', {hasCss: true});
declareExtension('amp-story', '0.1', {hasCss: true});
declareExtension('amp-story-auto-ads', '0.1', {hasCss: false});
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 we agreed not to have this as a separate binary. Can you move the code into the amp-story extension?

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, I guess we can move it later if it bloats

Copy link
Member Author

Choose a reason for hiding this comment

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

done

// temporary to be replaced with real page later
makeMockPage() {
const ampStoryAdPage = document.createElement('amp-story-page');
ampStoryAdPage.id = 'ad-page-1';
Copy link
Contributor

Choose a reason for hiding this comment

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

we need to make sure the id not conflict with existing element IDs on the page (provided by the publisher).
you can use our reserved prefix: i-amphtml-

Copy link
Member Author

Choose a reason for hiding this comment

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

done

const ampStory = this.element.parentElement;
user().assert(ampStory.tagName === 'AMP-STORY',
`<${TAG}> should be child of <amp-story>`);
ampStory.appendChild(this.makeMockPage());
Copy link
Contributor

Choose a reason for hiding this comment

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

we might want to do this in layoutCallback.

Copy link
Member Author

Choose a reason for hiding this comment

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

my thought was that we wanted to let the ad resources start loading ASAP but if you want layoutCallback SGTM

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

we want to be nice to let content render first.
we are not showing ads in the first 3 page views in anyway.

// temporary to be replaced with real page later
makeMockPage() {
const ampStoryAdPage = document.createElement('amp-story-page');
ampStoryAdPage.id = 'i-amphtl-ad-page-1';
Copy link
Contributor

Choose a reason for hiding this comment

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

typo amphtml.

@newmuis what do you think about this?
i-amphtml- is reserved ID prefix by validator. we can have i-amphtml-ad- as a prefix for all auto generated pages for ads.

this ID will be consumed by analytics.

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM. My question is just whether there's something more valuable than a numerical ID that publishers may want for analytics purposes, but I don't understand enough about how publishers consume/evaluate ads to be able to answer that.

Copy link
Contributor

@lannka lannka Feb 2, 2018

Choose a reason for hiding this comment

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

that's a good point.

maybe we should include the previous pageId into the ID? If the previous page has an ID of page-3, the ad ID becomes: i-amphtml-AD-page-3

when reporting to analytics, we strip out the i-amphtml- prefix. so publisher will see AD-page-3, so he can infer where the ad is shown.

Of course, we will never show 2 ads next to each other, for sake of user experience, also to make sure no ID conflicts between the ads.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like this idea, but I think to accomplish it we might need two pieces of identification, one to keep track of it before we know where it will be placed, and another that contains the placement data. Maybe we could use a different attr for one of these?

@@ -201,7 +201,8 @@ export class AmpStory extends AMP.BaseElement {
/** @param {!AmpElement} element */
constructor(element) {
super(element);


debugger;
Copy link
Contributor

Choose a reason for hiding this comment

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

debugger? :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

wow that last commit was sloppy

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@@ -41,7 +41,7 @@ export class NavigationState {
* @param {!Element} storyElement
* @param {function():Promise<boolean>} hasBookend
*/
constructor(storyElement, hasBookend) {
constructor(storyElement, hasBookend) {]de
Copy link
Contributor

Choose a reason for hiding this comment

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

woops

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@@ -201,7 +201,8 @@ export class AmpStory extends AMP.BaseElement {
/** @param {!AmpElement} element */
constructor(element) {
super(element);


debugger;
Copy link
Contributor

Choose a reason for hiding this comment

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

remove

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@@ -41,7 +41,7 @@ export class NavigationState {
* @param {!Element} storyElement
* @param {function():Promise<boolean>} hasBookend
*/
constructor(storyElement, hasBookend) {
constructor(storyElement, hasBookend) {]de
Copy link
Contributor

Choose a reason for hiding this comment

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

remove

Copy link
Member Author

Choose a reason for hiding this comment

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

done

/** @param {!AmpElement} element */
constructor(element) {
super(element);
this.ampStory = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Add JsDoc

Copy link
Member Author

Choose a reason for hiding this comment

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

done

// temporary to be replaced with real page later
makeMockPage() {
const ampStoryAdPage = document.createElement('amp-story-page');
ampStoryAdPage.id = 'i-amphtl-ad-page-1';
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: typo (missing "m": i-amphtml-ad-page-1)

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed


/** @override */
layoutCallback() {
this.ampStory.appendChild(this.makeMockPage());
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM for now. I don't think this is going to be sufficient long-term, since the amp-story won't know its children have changed. We'll need to devise a way to tell the story that it has a new page. You could either dispatch an event, or expose a function from AmpStory and call it here, like:

ampStory.getImpl().then(storyImpl => {
  storyImpl.addNewPage(this.makeMockPage());
});

Copy link
Contributor

Choose a reason for hiding this comment

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

In long term, maybe worth to extract a PageManager class to decouple the dependency.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@cramforce
Copy link
Member

This pull request introduces 1 alert - view on lgtm.com

new alerts:

  • 1 for Syntax error

Comment posted by lgtm.com

@calebcordry calebcordry merged commit 0aad6b4 into ampproject:master Feb 5, 2018
@calebcordry calebcordry deleted the story-auto-ad-skeleton branch February 5, 2018 21:26
protonate pushed a commit to protonate/amphtml that referenced this pull request Feb 26, 2018
* Component skeleton

* move files into amp-story

* clean up example

* remove bad link

* bad mock test

* clean up
RanAbram pushed a commit to RanAbram/amphtml that referenced this pull request Mar 12, 2018
* Component skeleton

* move files into amp-story

* clean up example

* remove bad link

* bad mock test

* clean up
protonate pushed a commit to protonate/amphtml that referenced this pull request Mar 15, 2018
* Component skeleton

* move files into amp-story

* clean up example

* remove bad link

* bad mock test

* clean up
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

6 participants