📈 Initial StorySpec Implementation#23030
Conversation
| "extraUrlParams": { | ||
| "param1": "Another value" | ||
| } | ||
| <script type="application/json"> |
There was a problem hiding this comment.
This file change is just fixing the indentation.
f05615e to
ae433e8
Compare
|
Hey @cvializ @zhouyx! I know you guys worked on the VideoSpec/VisibilitySpec, I was wondering if you could review the implementation I'm proposing here for the new AmpStorySpec. You can read more context in the issue #23032. I'm mostly interested in your feedback around the /cc @calebcordry |
| return; | ||
| } | ||
|
|
||
| if (repeat === false && eventsForPage[type] > 1) { |
There was a problem hiding this comment.
Instead of passing the eventsForPage as an array, can we pass eventsForPage[type] with the event details instead?
There was a problem hiding this comment.
Not sure I understand, can you elaborate more please?
There was a problem hiding this comment.
Sorry about the confusion.
If I understand it correctly, this.eventsPerPage_ is used to track how much time an event has occurred for each page here in amp-analytics. All we need is a boolean value indicating if the event has occurred before or not.
Is it possible for the amp-story to pass in that value whenever the analytics event is triggered, along with event.details?
There was a problem hiding this comment.
SGTM about using a boolean instead of a number, but I think @cvializ preferred (comment: aa90b03#r297751948) if this logic lived here, instead of it being in story-analytics.js.
@cvializ , are you OK with me moving it back to the story-analytics.js file?
There was a problem hiding this comment.
What @cvializ describes also makes sense to me. But when it comes to how many times an event has been triggered, the story knows the best.
I figure a special case can help us decide which way to proceed.
Think about the case where one put two <amp-analytics> element on the page, both listens to the story-page-view event for example, and has repeat equals to false
Say <amp-analytics id=1> got laid out very early, and had the listener ready before the first story-page-view event arrives. While <amp-analytics id=2> only got laid out after the first event arrives. (In theory this won't be an issue, because we buffer all events. But there's still a 10 seconds buffer time) But it still got the second the story-page-view.
What do you think the expected behavior should be. <amp-analytics id=2> still send out the event or not? Personally I'm leaning towards having story keep the count because there could be multiple amp-analytics elements, but only one story that's triggering the events.
There was a problem hiding this comment.
There was a problem hiding this comment.
👍 That sounds good. I thought repeat was a number and not a boolean
Enriqe
left a comment
There was a problem hiding this comment.
Thanks for the quick reviews! 😄
I tried to address all the comments, let me know if I missed something.
| return; | ||
| } | ||
|
|
||
| if (repeat === false && eventsForPage[type] > 1) { |
There was a problem hiding this comment.
Not sure I understand, can you elaborate more please?
|
Friendly ping :) |
cvializ
left a comment
There was a problem hiding this comment.
LGTM. I don't see any tests, could be good to add in a follow up
|
Rebasing this PR since it's been sitting for a while. Will add tests in a follow-up :) |
zhouyx
left a comment
There was a problem hiding this comment.
Sorry about the delay. Have two comments, but LGTM.
| return; | ||
| } | ||
|
|
||
| if (repeat === false && eventsForPage[type] > 1) { |
There was a problem hiding this comment.
Sorry about the confusion.
If I understand it correctly, this.eventsPerPage_ is used to track how much time an event has occurred for each page here in amp-analytics. All we need is a boolean value indicating if the event has occurred before or not.
Is it possible for the amp-story to pass in that value whenever the analytics event is triggered, along with event.details?
|
Sorry just got back to this, @zhouyx can you please take a look? |
| const details = /** @type {?JsonObject|undefined} */ (getData(event)); | ||
| const detailsForPage = details['detailsForPage']; | ||
|
|
||
| if (repeat === false && detailsForPage['repeated']) { |
|
Ready for another review @zhouyx 👍 |
zhouyx
left a comment
There was a problem hiding this comment.
LGTM. But I just noticed there's no unit test for the change, any idea on how to add test coverage?
|
Thanks! Was going to add them as a follow up but I figured there's no rush. Just added them in the latest commit 👍 |
| const event = new Event('story-page-visible'); | ||
| event.data = defaultVars; | ||
|
|
||
| tracker.sessionObservable_.fire(event); |
There was a problem hiding this comment.
Re: using private properties during tests
Is there a way to dispatch the event rather than triggering the listener yourself?
There was a problem hiding this comment.
I tried triggering the event myself but it wasn't working, the observable wasn't receiving the event. Let me know if you have any other ideas.
There was a problem hiding this comment.
I'm not very familiar with the analytics code, but the fact that the listener isn't receiving the event in the should listen on story events test is pretty worrying :(
Just wanted to point this out, maybe it's fine, I'll let you and the owners decide :)
There was a problem hiding this comment.
Not super familiar with the analytics code either, but I did see usage of some private properties in this file, which is why I thought it was fine. @zhouyx do you have any thoughts on this?
There was a problem hiding this comment.
Could you try tracker.trigger()?
There was a problem hiding this comment.
Hmm, the AmpStoryEventTracker doesn't have that method, am I missing something?
There was a problem hiding this comment.
oops, sorry i got confused with the customEventTracker. Nvm of the trigger() method.
I tried triggering the event myself but it wasn't working
Could you explain how you are triggering the event? My quick guess is the event is not dispatched from within the analytics root, but from the window.
There was a problem hiding this comment.
const rootEl = root.getRootElement();
rootEl.dispatchEvent(event);
expect(analyticsEvent).to.be.calledOnce; // Not being called.
Tried different variations of this, let me know if I'm doing something wrong.
There was a problem hiding this comment.
Oh, it works using root.getRoot() but not with root.getRootElement() 🤔 I should've known better since the listener is installed with root.getRoot(), I just thought that root.getRootElement() would be in the same scope... my bad.
|
If there aren't any other comments I'll go ahead and merge this, thanks all for the reviews! 👍 |
* initial storyspec implementation * Reviews * Improve readability. * Use map() for eventsPerPage_ * Move logic of updating event counts per page to the tracker. * fix dep error by moving StoryAnalytics to src/analytics * assert absence of selector and default to :root * fix typo * move getdetails back to the story side * reviews * add tests * split tests, only assert repeated field * dispatch the event using getRoot in the test
This reverts commit 1a3eb26.
…cript-img-with-http-protocol * 'master' of github.com:ampproject/amphtml: (1326 commits) Fix and enable e2e tests for AMPHTML ads FIE rendering mode (ampproject#23995) 🏗 Update WorkerDOM to 0.17.0 (ampproject#24024) Make DocInfo.pageViewId64 async (ampproject#23998) 🐛 Updates amp-sidebar in amp-story (ampproject#23956) Revert "Revert "📖Update documentation for carousel 0.2 (ampproject#23840)" (ampproject#23967)" (ampproject#24016) 🔥 Revert "📈 Initial StorySpec Implementation (ampproject#23030)" (ampproject#24013) Extension skeleton code for payment widgets (ampproject#23045) 🏗🐛 Don't call `travisBuildNumber()` in the global scope (ampproject#24021) Remove suppressTypes from amp-mustache. (ampproject#23993) 🐛 Move `terser` from `dependencies` to `devDependencies` (ampproject#24018) Revert "Revert "Set the new loaders experiment to 1% of traffic. (ampproject#23780)" (ampproject#23963)" (ampproject#24014) SwG release 0.1.22.63 (ampproject#23997) Resolve navTiming variable earlier if possible (ampproject#23580) 🏗 Don't run all the runtime tests for validator-only changes (ampproject#24010) Collect document ready signal (ampproject#23981) Validator rollup (ampproject#24000) Remove flaky story branching test. (ampproject#23994) Include amp-base-carousel in amp-carousel's build. (ampproject#23984) Partial validator rollup (ampproject#23996) amp-bind: Rate-limit history operations (ampproject#23938) ...
Closes #23032