-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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 reports wrong cid when multiple tags present #25525
Comments
/cc @ampproject/wg-analytics |
Thanks for reporting. That definitely sounds like a bug to me. @micajuine-ho let's dig deeper into this after the CCPA work. |
Does it still happen when using the amp-analytics variable instead of the platform variable, e.g.:
(...assuming that I'm reading the docs correctly and this is valid syntax in the first place) |
Sorry for the delay @mbrowne . I just confirmed that the issue still exists when using |
I am investigating now. We think it might have something to do with the caching implementation of scope client id. Will update when I make progress |
Hi @mattwomple, it seems that GA creates a _ga cookie, but then the custom amp-analytics tag creates a scope cookie through So both the custom analytics and googleanalytics tag return the amp provided scope cookie. An easy way to fix this would be in the custom config change What do you think about this? |
@micajuine-ho Thanks for the analysis. Based on your suggestion, I tested the following
I'll start with: Thanks, I appreciate the workaround. I can share the
Isn't the behavior of
These inconsistent results when visiting the AMP page suggest there is still something not behaving correctly. Do you agree? |
It actually finds the cookie value
On the first visit to Visit the AMP page with last:
On the second visit:
I'm not sure if this is the correct behavior but this it why it's happening. I've been told that the optional cookiename parameter was added for backwards compatibility sake, and that this final design is not the most optimal. |
@micajuine-ho Thanks for taking the time to spell out the actions taken by amphtml/src/service/cid-impl.js Lines 411 to 417 in 4917e70
I can see a few options for improvement. Let me know if you think any of these are worth consideration:
|
@mattwomple I think that the third option is the way to go, as it involves no changes to the runtime, which could have unintended side effects to existing users. Additionally, looking through the our list of vendor configs, there are only 4 analytics vendors who use the macro CLIENT_ID(AMP_ECID_GOOGLE,,_ga) (including googleanalytics and gtag). No other vendors use the the optional cookie name parameter. To me this indicates that it is the intended behavior for these vendors to use the _ga cookie created by googleanalytics. @zhouyx What are your thoughts on how to proceed? |
Read the thread. Thank you both for the detailed explanation. Can I summarize the issue to how should CLIENT_ID(scope, , opt_cookieName) behave. Current order: This caused inconsistency with different tag orders and even with multiple page load. My understanding is that the cachedCid is a must because we need to keep the value same for all. And then we want to stick to the existing cookie if possible. @lannka Do you recall why we need a Also add @zikas for ideas. |
CID API accepts two scopes. You can think of them as a required off-origin cookie scope (AMP cache), and an optional origin cookie scope. We started with only one cookie scope, which is the In the GA case, they provide both the
Since we’ve agreed that the provided optional cookie name should override the scope value. I think it makes sense to always return the value from opt_cookieName if it exists. But still, in my understanding the |
PR #26130 is a reasonable approach to this problem. Cookie first, scope second, else generate new cookie and scope. From my earlier comment, the updated behavior would be:
Importantly, these results are consistent in both |
What's the issue?
Session stitching from non-AMP to AMP pages breaks if the AMP page contains multiple
<amp-analytics>
tags and the first tag usesCLIENT_ID()
to set a variable.How do we reproduce the issue?
Create a non-AMP page that uses Google Analytics via
analytics.js
.Create an AMP page with
<amp-analytics>
utilizingCLIENT_ID()
to set a variable, e.g."vars": { "vid": "CLIENT_ID(AMP_ECID_GOOGLE)" }
. Append<amp-analytics type="googleanalytics">
just after the first<amp-analytics>
tag.https://www.google-analytics.com/r/collect
beacon for thecid
reported.https://www.google-analytics.com/r/collect
beacon for thecid
reported.Here is a minimal example the demonstrates the issue.
cmphys.com
cid
set in cookie_gl
and sent in beacon www.google-analytics.com/r/collectcid
sent in beacon www.google-analytics.com/r/collectThe order of the
<amp-analytics>
scripts changes the outcome. If you put<amp-analytics type="googleanalytics">
before the custom<amp-analytics>
tag, the correctcid
is used in thegoogleanalytics
beacon. This can be tested in the sample website above by clicking "Visit the AMP page with <amp-analytics type="googleanalytics"> first" from the non-AMP page.What browsers are affected?
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36
Which AMP version is affected?
1911062056110
The text was updated successfully, but these errors were encountered: