-
Notifications
You must be signed in to change notification settings - Fork 1
AMP configuration #3
Comments
I see one big challenge when considering the AMP configuration. |
Thanks a lot for your quick response. That's unfortunate, but I have some hopes with this: https://amp.dev/documentation/components/amp-script/ |
I was able to add an amp-script element on the page, so I guess it gets executed. The problem is though that it doesn't seem possible to add the |
If I understand correctly it's not possible to access the amp-script tag from the Javascript. But what's inside the amp-script tag can be accessed. Could you add another way to pass the pe-ua in that way? Eg. |
Thank you so much for your investigations and good news so far. <!-- test.html -->
<script src="./test.js"></script> // test.js
console.log(document.currentScript.attributes.getNamedItem("src").value); I wonder whether AMP doesn't support access to the script at all or it only rejects access to custom attributes. In effect, if the former is true, we can configure the CDN so that the query strings are not interpreted. Then, we can patch the existing configuration retrieval mechanism to support extracting info from the query string at the client side. |
This logs: I extended their amp hello world example and this works:
I did it as an inline script for faster debugging, but afaik an external script should work the same. |
Without the button stuff and on page load:
|
When using I may have also found an alternative path that is more straightforward. Let's use the <!DOCTYPE html>
<html amp>
<head>
<!-- AMP boilerplate omitted ... -->
<script
async
custom-element="amp-analytics"
src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"
></script>
</head>
<body>
<amp-analytics>
<script type="application/json">
{
"requests": {
"base": "https:/ENDPOINT/ua/UA-XXXXXXXX-YY/anonymize"
},
"transport": {
"beacon": true,
"useBody": true
},
"triggers": {
"trackPageview": {
"on": "visible",
"request": "base",
"extraUrlParams": {
"title": "TITLE",
"url": "CANONICAL_URL",
"referrer": "DOCUMENT_REFERRER"
}
}
}
}
</script>
</amp-analytics>
</body>
</html> The amount of todos for this solution is pretty small. We need to update the server-side so that JSON payloads are also accepted. There are also a few drawbacks that can be overcome. In effect, the current js tracker is very conservative in terms of the amount of data leaking from the current and the referrer URL, while AMP doesn't care too much:
Let me know what you think. |
@fsenart Wow thank you so much for having such a detailed look into this, I am amazed! |
@fsenart Let me know if I can be of any help, looking very much forward to the AMP integration. |
Sorry for the delay. I've been pretty busy these days. I'm on it; keep connected. |
Thanks a lot for the feedback, I can totally understand, and I am just super thankful that you take this extra work besides your normal dayjob. Thank you for this project, I am very eager to try it out, whenever it is ready :) |
- Extract payload from body and query string - Decode payload as JSON or URL encoded - Strip query string from document URL - Strip path and query string from referrer URL See: #3 Signed-off-by: Farzad Senart <515714+fsenart@users.noreply.github.com>
@dreamflasher it's shipped! If you are using the EE<!DOCTYPE html>
<html amp lang="en">
<head>
<meta charset="utf-8" />
<script async src="https://cdn.ampproject.org/v0.js"></script>
<title>Hello, AMPs</title>
<link
rel="canonical"
href="https://amp.dev/documentation/guides-and-tutorials/start/create/basic_markup/"
/>
<meta name="viewport" content="width=device-width" />
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "NewsArticle",
"headline": "Open-source framework for publishing content",
"datePublished": "2015-10-07T12:02:41Z",
"image": ["logo.jpg"]
}
</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
custom-element="amp-analytics"
src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"
></script>
</head>
<body>
<amp-analytics>
<script type="application/json">
{
"requests": {
"base": "https://proxy.privera.io/ua/${UA_PROPERTY}/anonymize"
},
"vars": {
"UA_PROPERTY": "UA-XXXXXXXXX-Y"
},
"transport": {
"beacon": true,
"useBody": true
},
"triggers": {
"trackPageview": {
"on": "visible",
"request": "base",
"extraUrlParams": {
"type": "page",
"title": "TITLE",
"url": "CANONICAL_URL",
"referrer": "DOCUMENT_REFERRER"
}
}
}
}
</script>
</amp-analytics>
</body>
</html> If you are using the CE<!-- ... -->
<script type="application/json">
{
"requests": {
"base": "API_ENDPOINT/anonymize"
},
"transport": {
"beacon": true,
"useBody": true
},
"triggers": {
"trackPageview": {
"on": "visible",
"request": "base",
"extraUrlParams": {
"type": "page",
"title": "TITLE",
"url": "CANONICAL_URL",
"referrer": "DOCUMENT_REFERRER"
}
}
}
}
</script>
<!-- ... --> Please try the feature and report back any unexpected behavior. I will update the documentation once everything is ok. |
Wow! Amazing! You're the best! Ah CE=Community Editition/self-hosted, EE=Enterprise |
I removed the boilerplate to create a smaller example that can be used for the docs:
|
@fsenart You made my day! It works like a charm. Great work, Sir! |
What's the correct AMP configuration? (https://amp.dev/documentation/components/amp-analytics/)
Also I am opening a ticket at AMP that they add you as a vendor: ampproject/amphtml#33779
The text was updated successfully, but these errors were encountered: