Skip to content

📈 Initial StorySpec Implementation#23030

Merged
Enriqe merged 10 commits intoampproject:masterfrom
Enriqe:story-analytics1
Jul 19, 2019
Merged

📈 Initial StorySpec Implementation#23030
Enriqe merged 10 commits intoampproject:masterfrom
Enriqe:story-analytics1

Conversation

@Enriqe
Copy link
Copy Markdown
Contributor

@Enriqe Enriqe commented Jun 26, 2019

Closes #23032

@Enriqe Enriqe self-assigned this Jun 26, 2019
"extraUrlParams": {
"param1": "Another value"
}
<script type="application/json">
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file change is just fixing the indentation.

@Enriqe Enriqe force-pushed the story-analytics1 branch 2 times, most recently from f05615e to ae433e8 Compare June 26, 2019 15:14
@Enriqe Enriqe marked this pull request as ready for review June 26, 2019 15:17
@Enriqe
Copy link
Copy Markdown
Contributor Author

Enriqe commented Jun 26, 2019

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 events.js file and if I'm making a correct transition from the CustomEventTracker class to the new AmpStoryEventTracker class I created (which is very similar to the VideoEventTracker).

/cc @calebcordry

Copy link
Copy Markdown
Contributor

@cvializ cvializ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! A few questions

return;
}

if (repeat === false && eventsForPage[type] > 1) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of passing the eventsForPage as an array, can we pass eventsForPage[type] with the event details instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand, can you elaborate more please?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

@Enriqe Enriqe Jul 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#23030 (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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point and a use case I didn't think about (having two amp-analytics elements). I will change it back so that amp-story has the count of events per page - and change it to be a boolean instead of a number. Does this sound good to you? @zhouyx @cvializ

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 That sounds good. I thought repeat was a number and not a boolean

Copy link
Copy Markdown
Contributor Author

@Enriqe Enriqe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand, can you elaborate more please?

@Enriqe
Copy link
Copy Markdown
Contributor Author

Enriqe commented Jun 28, 2019

Friendly ping :)

Copy link
Copy Markdown
Contributor

@cvializ cvializ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I don't see any tests, could be good to add in a follow up

@Enriqe Enriqe force-pushed the story-analytics1 branch from 08df324 to 9166277 Compare July 8, 2019 16:01
@Enriqe
Copy link
Copy Markdown
Contributor Author

Enriqe commented Jul 8, 2019

Rebasing this PR since it's been sitting for a while. Will add tests in a follow-up :)

Copy link
Copy Markdown
Contributor

@zhouyx zhouyx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about the delay. Have two comments, but LGTM.

return;
}

if (repeat === false && eventsForPage[type] > 1) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@Enriqe Enriqe force-pushed the story-analytics1 branch from 9e74827 to 26926bb Compare July 15, 2019 22:01
@Enriqe
Copy link
Copy Markdown
Contributor Author

Enriqe commented Jul 15, 2019

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']) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the change!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Np!

@Enriqe
Copy link
Copy Markdown
Contributor Author

Enriqe commented Jul 16, 2019

Ready for another review @zhouyx 👍

Copy link
Copy Markdown
Contributor

@zhouyx zhouyx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. But I just noticed there's no unit test for the change, any idea on how to add test coverage?

Enriqe added 5 commits July 17, 2019 16:27
* Improve readability.
* Use map() for eventsPerPage_
* Move logic of updating event counts per page to the tracker.
@Enriqe Enriqe force-pushed the story-analytics1 branch from c269beb to ad267ba Compare July 18, 2019 15:38
@Enriqe
Copy link
Copy Markdown
Contributor Author

Enriqe commented Jul 18, 2019

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re: using private properties during tests
Is there a way to dispatch the event rather than triggering the listener yourself?

Copy link
Copy Markdown
Contributor Author

@Enriqe Enriqe Jul 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you try tracker.trigger()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the AmpStoryEventTracker doesn't have that method, am I missing something?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

      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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Enriqe
Copy link
Copy Markdown
Contributor Author

Enriqe commented Jul 19, 2019

If there aren't any other comments I'll go ahead and merge this, thanks all for the reviews! 👍

@Enriqe Enriqe merged commit 1a3eb26 into ampproject:master Jul 19, 2019
rindo pushed a commit to logly/amphtml that referenced this pull request Jul 24, 2019
* 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
Enriqe added a commit to Enriqe/amphtml that referenced this pull request Aug 16, 2019
Enriqe added a commit that referenced this pull request Aug 16, 2019
* Revert "📈 Initial StorySpec Implementation (#23030)"

This reverts commit 1a3eb26.

* fix import

* fix test
dreamofabear pushed a commit that referenced this pull request Aug 16, 2019
* Revert "📈 Initial StorySpec Implementation (#23030)"

This reverts commit 1a3eb26.

* fix import

* fix test
dreamofabear pushed a commit that referenced this pull request Aug 16, 2019
* Revert "📈 Initial StorySpec Implementation (#23030)"

This reverts commit 1a3eb26.

* fix import

* fix test
westonruter added a commit to westonruter/amphtml that referenced this pull request Aug 17, 2019
…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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support configurable options for analytics in amp-story

6 participants