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

Improve fake ad network by providing working example, updating doc, a… #9295

Merged
merged 5 commits into from Jun 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions build-system/app.js
Expand Up @@ -832,13 +832,10 @@ app.use([cloudflareDataDir], function fakeCors(req, res, next) {
*/
app.get([fakeAdNetworkDataDir + '/*', cloudflareDataDir + '/*'], (req, res) => {
let filePath = req.path;
let unwrap = false;
if (req.path.endsWith('.html')) {
filePath = req.path.slice(0,-5);
unwrap = true;
}
let unwrap = !req.path.endsWith('.html');
filePath = pc.cwd() + filePath;
fs.readFileAsync(filePath).then(file => {
res.setHeader('X-AmpAdRender', 'nameframe');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Copying comment over from outdated code, with slight edits for clarity)
@lannka Re: your previous question, it turns out that the problem was here. "unwrap" was implemented backwards. If the creative is a .json file, then it should be unwrapped (signature and HTML extracted), and if it's a .html file then that is not needed (and the extension should NOT be stripped off). But "unwrap" was done the opposite way. My other main change here is the line that sets the X-AmpAdRender header, which removes the need for the change to amp-a4a.js which you weren't a fan of. Now,

const method = fetchResponse.headers.get(RENDERING_TYPE_HEADER) ||
sets method correctly, and we don't hit the error on line 615.

Copy link
Contributor

Choose a reason for hiding this comment

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

much better. appreciate that.

if (!unwrap) {
res.end(file);
return;
Expand Down
24 changes: 24 additions & 0 deletions examples/fake-ad.amp.html
@@ -0,0 +1,24 @@
<!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.

actually, would you move this file to test/manual/fakeada4a.amp.html, to sit together with test/manual/fakead3p.amp.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do customers know to look there? What is the intended difference between an example and a manual test?

Copy link
Contributor

Choose a reason for hiding this comment

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

example/ is for AMP page authors.
test/manual is for us.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My preference would be to leave it in examples/ so that an AMP page author that wants to write a page and test including ads in it can use this. But it's up to you. Do you think this is valid/useful?

<html ⚡>
<head>
<meta charset="utf-8">
<title>Fake Ad Network Test</title>
<link rel="canonical" href="amps.html" >
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Georgia|Open+Sans|Roboto' rel='stylesheet' type='text/css'>
<script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<script async src="https://cdn.ampproject.org/v0.js"></script>
</head>
<body>
<h2>Fake Ad Network:</h2>
<amp-ad width="300" height="400"
type="fake"
src="fake_amp.json"
data-use-a4a="true">
<div placeholder>Loading...</div>
<div fallback>Could not display the fake ad :(</div>
</amp-ad>
<br/>
</body>
</html>
Expand Up @@ -67,7 +67,6 @@ export class AmpAdNetworkFakeImpl extends AmpA4A {
};
}
}

// Normal mode: the content is a JSON structure with two fieleds:
// `creative` and `signature`.
const decoded = JSON.parse(deserialized);
Expand Down
Expand Up @@ -47,6 +47,8 @@ fields: `"creative"` and `"signature"`. The `signature` field **must** be a
valid signature for the text of the `creative` field, according to at least
one of the built-in A4A keys. (_Note:_ A4A will discontinue built-in keys
when the ability to fetch keys live from the validation service is available.)
Alternatively, the `<amp-ad type="fake">` tag may include the attribute
`fakesig="true"` to disable signature checking.

## Attributes

Expand Down