Skip to content

Instantly share code, notes, and snippets.

@mizchi
Last active November 30, 2019 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizchi/45543f0e6bafd2bcfba5df7e8bb0b4f2 to your computer and use it in GitHub Desktop.
Save mizchi/45543f0e6bafd2bcfba5df7e8bb0b4f2 to your computer and use it in GitHub Desktop.
const express = require('express');
const app = express();
app.use(express.json());
app.use((_req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
next();
});
app.post("/amp/view", (req, res) => {
const u = url.parse(req.query.url);
console.log(u);
res.send("ok");
});
app.listen(13999)
<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>
<amp-analytics data-credentials="include">
<script type="application/json">
{
"vars": {
"api_key": "dummy"
},
"requests": {
"view": "http://localhost:13999/amp/view?url=${canonicalUrl}&api_key=${api_key}&id=$RANDOM"
},
"triggers": {
"view": {
"on": "visible",
"request": "view"
}
},
"transport": {
"xhrpost": true
}
}
</script>
</amp-analytics>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment