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

amp-analytics fires only occasionally in amp-ad-custom #26643

Closed
mwakkiy opened this issue Feb 6, 2020 · 9 comments
Closed

amp-analytics fires only occasionally in amp-ad-custom #26643

mwakkiy opened this issue Feb 6, 2020 · 9 comments
Assignees
Labels
Stale Inactive for one year or more Type: Bug WG: monetization

Comments

@mwakkiy
Copy link
Contributor

mwakkiy commented Feb 6, 2020

What's the issue?

amp-analytics fires only occasionally in amp-ad-custom

How do we reproduce the issue?

I've made this sample.
https://test.ms-rd.com/amp/amp-ad-custom/test01.html

  1. Reload page several times

  2. amp-analytics fires only occasionally
    When amp-analytics is successful, there is a request at the following URL.
    https://b94.yahoo.co.jp/1/m?
    https://b94.yahoo.co.jp/1/v?

What browsers are affected?

All browsers

Which AMP version is affected?

Version 2001281851410

@micajuine-ho
Copy link
Contributor

@lannka We took a look at this issue, but think that it's probably ads related rather than analytics related. Would you mind taking a look?

@lannka
Copy link
Contributor

lannka commented Jun 9, 2020

sure, looking

@lannka
Copy link
Contributor

lannka commented Jun 9, 2020

while still looking, some early finding is a race condition between the loading of amp-analytics.js script and the injection of <amp-analytics> in FIE.

@lannka
Copy link
Contributor

lannka commented Jun 11, 2020

it is because the factory method for amp-analytics's services didn't get run in that case

addDocFactory(factory, opt_forName) {
const holder = this.getCurrentExtensionHolder_(opt_forName);
holder.docFactories.push(factory);
// If a single-doc mode, run factory right away if it's included by the doc.
if (this.currentExtensionId_ && this.ampdocService_.isSingleDoc()) {
const ampdoc = this.ampdocService_.getAmpDoc(this.win.document);
const extensionId = dev().assertString(this.currentExtensionId_);
// Note that this won't trigger for FIE extensions that are not present
// in the parent doc.
if (ampdoc.declaresExtension(extensionId) || holder.auto) {
factory(ampdoc);
}
}
}

It happens when the amp-analytics.js script gets loaded before the <amp-analytics> element gets injected in the FIE iframe.

because <amp-analytics> element is injected dynamically, it missed the opportunity to get stubbed during stubElementsForDoc time.

if (
isStub(this.implementation_) &&
!ampdoc.declaresExtension(extensionId)
) {
Services.extensionsFor(win).installExtensionForDoc(
ampdoc,
extensionId
);
}
}

so <amp-analytics> is not stubbed, so the isStub call returns false which prevents installExtensionForDoc from being run.

@dvoytenko @choumx did I miss anything here? is a dynamically injected AMP element supposed to be stubbed if the extension is already fully loaded on the page?

@dreamofabear
Copy link

Sorry I'm not familiar with amp-analytics injection in FIE. Is the code above the correct, non-racy path? FIE doesn't actually call installExtensionForDoc itself and relies on custom-element.js?

@dvoytenko
Copy link
Contributor

@lannka I don't think this is the reason here. I'll need to debug this. Do you have a good localdev repro instructions?

@lannka
Copy link
Contributor

lannka commented Jun 15, 2020

@dvoytenko I pushed a branch for testing. pls check out #28882

and thanks for helping!

@lannka
Copy link
Contributor

lannka commented Jun 22, 2020

Discussed with @dvoytenko offline, we both believe the launch of ampdoc-fie experiment will fix the issue. It's not worth at this time to add additional hacks to fix amp-ad-custom. We will prioritize the launch of ampdoc-fie instead.

@stale
Copy link

stale bot commented Dec 14, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale Inactive for one year or more label Dec 14, 2021
@stale stale bot closed this as completed Dec 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale Inactive for one year or more Type: Bug WG: monetization
Projects
None yet
Development

No branches or pull requests

5 participants