amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

context.canonicalUrl seems not useful in building an amp-ad

Open bobcassels opened this issue 10 years ago • 8 comments

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?

bobcassels avatar Feb 04 '16 14:02 bobcassels

Canonical URL should be whatever the <link rel=canonical href="THIS VALUE"> of the embedding doc is.

cramforce avatar Feb 04 '16 15:02 cramforce

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.

cramforce avatar Feb 04 '16 15:02 cramforce

Oops. My example page was copied from another example. I didn't notice the <link rel=...>

Never mind.

bobcassels avatar Feb 04 '16 19:02 bobcassels

@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 avatar Oct 06 '17 08:10 monish-chhadwa

@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.

cramforce avatar Oct 06 '17 16:10 cramforce

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

monish-chhadwa avatar Oct 06 '17 17:10 monish-chhadwa

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

monish-chhadwa avatar Oct 06 '17 17:10 monish-chhadwa

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 .

cramforce avatar Oct 06 '17 18:10 cramforce