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

✨Allow fake ads in amp stories #21025

Merged
merged 4 commits into from Apr 5, 2019
Merged

✨Allow fake ads in amp stories #21025

merged 4 commits into from Apr 5, 2019

Conversation

calebcordry
Copy link
Member

Before this change the ad would not render due to incorrect metadata around the ctaType and ctaUrl.

This allows a configuration like the following to render

<amp-story-auto-ads>
  <script type="application/json">
    {
      "ad-attributes": {
        "type": "fake",
        "src": "/path/to/story/ad",
        "id": "i-amphtml-demo-fake",
        "a4a-conversion": true
      }
    }
  </script>
</amp-story-auto-ads>

@calebcordry
Copy link
Member Author

cc/ @ithinkihaveacat @kul3r4

"ad-attributes": {
"type": "fake",
"src": "/examples/amp-story/ads/app-install.html",
"id": "i-amphtml-demo-fake",
Copy link
Contributor

Choose a reason for hiding this comment

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

Does amp-story-auto-ads check the validness of the id?

Copy link
Member Author

Choose a reason for hiding this comment

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

amp-story-auto ads just creates an <amp-ad type="fake" id="i-amphtml..">. There is no additional logic around checking the id, so it should behave the same as a normal "fake" ad. Are you worried about the doc being invalid?

Copy link
Member Author

Choose a reason for hiding this comment

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

After thinking about this more, I think I understand. The doc will be valid when it shouldn't be. I don't have a great solution. We could have the runtime not allow this in certain contexts, but I'm not sure what the signal would be. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

To allowing fake ad specifically we can have some kind of workaround. For example, one must put id=i-amphtml-... to the <amp-story-auto-ads> component. So the fake ad only loads for invalid AMP page.

However i think this is related to #20003. Allowing developers to randomly assign attribute of the inserted ad in general sounds very unsafe to me. I can easily inject something like i-amphtml-ghost without validator catching that.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a good point. I agree a whitelist sounds good, but needs to be fleshed out. For instance id is allowed, but certain values are not. I will make some comments on the issue.

To solve this problem I think that having an invalid signal on the amp-story-auto-ads tag is a good idea. I will refactor.

Copy link
Contributor

Choose a reason for hiding this comment

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

SG. Thank you

Copy link
Contributor

Choose a reason for hiding this comment

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

a different issue: are we inserting multiple amp-ad with the same ID?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, is this not ok for testing?

Copy link
Member Author

Choose a reason for hiding this comment

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

changed this around a bit so auto ads injects a unique id. Pubs just add the attribute to the auto-ads tag itself.

@lannka
Copy link
Contributor

lannka commented Mar 6, 2019

@calebcordry what's the status of this PR?

@calebcordry
Copy link
Member Author

I got distracted by other things :) I need to refactor this to make sure the doc is invalid when in use. This is very helpful for me / devrel when working on making these creatives so I will get it done.

@calebcordry
Copy link
Member Author

@zhouyx Could you re-review when you have a chance?

@calebcordry calebcordry requested review from torch2424 and removed request for lannka March 25, 2019 18:18
Copy link
Contributor

@torch2424 torch2424 left a comment

Choose a reason for hiding this comment

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

Just a few questions / suggestions 😄

Thanks!

@@ -0,0 +1,101 @@
<!doctype html>
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this example related to the fake ads? 🤔 No worries if it isn't just curious 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the fake ad that gets loaded.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh haha! Rad! Sounds good 😄

@@ -334,6 +336,10 @@ export class AmpStoryAutoAds extends AMP.BaseElement {
*/
schedulePage_() {
const page = this.createAdPage_();
if (!page) {
// Creation of ad has failed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we throw an error or warning here? 🤔

It may be a bit noisy though if we did.

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 think this should only happen in the fake case which will already user().warn()

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me! 😄

const id = this.element.getAttribute('id');
if (!id || !startsWith(id, 'i-amphtml-demo-')) {
user().warn(TAG, 'id must start with i-amphtml-demo- to use fake ads');
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Have we handle the case where this.createAdElement_ returns null?

const ampAd = this.createAdElement_();

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope you are right, null check was in wrong place. Instead of adding a bunch of logic for fake ad destruction, what do you think about creating a dummy element instead like <p>Fake ad discarded.<p> and inserting that?

Copy link
Contributor

Choose a reason for hiding this comment

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

What about we keep it simple, and use userAssert() instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. Done.

@zhouyx
Copy link
Contributor

zhouyx commented Mar 26, 2019

LGTM
Depending on who you expect to use this feature, it may worth documenting (doc or error message) that we require an invalid AMP doc to use fake ad.

@calebcordry calebcordry merged commit bbabe0a into ampproject:master Apr 5, 2019
@calebcordry calebcordry deleted the stories-fake branch April 5, 2019 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants