context.canonicalUrl seems not useful in building an amp-ad
I'm working on ads/adsense.js, the thing that makes an Adsense ad request. When I run an example, the value I get for context.canonicalUrl seems useless:
global.context.canonicalUrl: http://nonblocking.io/ global.context.location.href: http://localhost:8000/examples.build/adsense.amp.max.html
So I'm using global.context.location.href for now. Is that right? Or is context.canonicalUrl wrong?
Canonical URL should be whatever the <link rel=canonical href="THIS VALUE"> of the embedding doc is.
The thing about location.href is that it will vary based on embedding context, which means you would treat a doc served through the AMP cache differently from a doc that is not.
Oops. My example page was copied from another example. I didn't notice the <link rel=...>
Never mind.
@cramforce As you said, I have noticed that for a doc served through AMP cache has a very different location.href than that which is not. But what if I want to access the actual url of the page. My use case is that I want to run a test mode based on some parameter that a user would specify in the url(in the query string part or hash part). How do I do that for cases when the amp html is served through google's cache?
@monish-chhadwa Are you inside an ad? There context.sourceUrl gives you the URL of the doc, independent of whether you are on the cache. On the AMP page SOURCE_URL is available in analytics for the same purpose.
I tried context.sourceUrl as well, but if i append a get parametere to the page on top, i still can't see it. In fact, i couldn't see it in any of the possible context variables
Sample url: https://www.google.com/amp/s/mobile.nytimes.com/2017/08/21/world/europe/spain-catalunya-barcelona-imam.amp.html?test_monish=123
And yes, I am inside an ad
This should work: https://mobile-nytimes-com.cdn.ampproject.org/c/s/mobile.nytimes.com/2017/08/21/world/europe/spain-catalunya-barcelona-imam.amp.html?test_monish=123
The query params on the google.com/amp URL aren't directly merged into the AMP cache URL (there is additional encoding)
On Fri, Oct 6, 2017 at 10:05 AM, monish-chhadwa [email protected] wrote:
Sample url: https://www.google.com/amp/s/mobile.nytimes.com/2017/08/21/ world/europe/spain-catalunya-barcelona-imam.amp.html?test_monish=123
And yes, I am inside an ad
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ampproject/amphtml/issues/1777#issuecomment-334813880, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFeT_BYahWIItKLEAN-AtelXKk1M-wMks5spl3TgaJpZM4HTcGF .