Skip to content

Conversation

bramanudom
Copy link
Contributor

With branching, we'd like to be able to track how the user navigates through a story.
This PR adds variables:

  • that indicates what page the user was coming from during a navigation (if any)
  • that indicates what AdvancementMode was used to perform a navigation (manual advancement, time-based auto-advancement, media-based auto-advancement, the "go to page" action)

#20083

STORY_PAGE_COUNT: 'storyPageCount',
STORY_IS_MUTED: 'storyIsMuted',
STORY_PROGRESS: 'storyProgress',
STORY_PREVIOUS_PAGE_ID: 'storyPreviosPageId',
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: typo on "previous"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

AUTO_ADVANCE_MEDIA: 'autoAdvanceMedia',
MANUAL_ADVANCE: 'manualAdvance',
ADVANCE_TO: 'advanceTo',
ADVANCE_TO_ADS: 'advanceToAds',
Copy link
Contributor

@newmuis newmuis Jan 24, 2019

Choose a reason for hiding this comment

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

nit: this reads like it is saying the advancement was to an ad, where you're really saying the advancement was from an ad with the advance-to attribute. Since publishers don't set the advance-to attribute for ads (it's set by us internally), I'm not sure the advance-to part is necessary to tell them here.

Maybe we can rename this to something like 'manualAdvanceFromAd'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this! You're right that the variable name is misleading.

Done.

/**
* @param {AdvancementMode} mode
*/
onAdvancementModeStateChange(mode) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can remove this (and the call to it on line 546 of amp-story.js), since we don't want to actually trigger a new analytics ping when the advancement mode changes. Updating the variable service should be sufficient; then when the next analytics trigger fires (e.g. when the story changes pages, or when the user unmutes the story, or when the user hits the bookend, etc), the variables will be populated because of the rest of what you've done here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for taking the time to explain this. Makes a lot of sense, and removed.

pageIndex,
this.getPageCount(),
targetPage.element.id,
oldPage.element.id,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can oldPage be undefined and trigger an error, eg: on first navigation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this, I went ahead and moved the code to avoid this problem.

if (oldPage.element.hasAttribute(advanceAttr)) {
this.storeService_.dispatch(
Action.SET_ADVANCEMENT_MODE,
AdvancementMode.ADVANCE_TO);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious about the product decision: Is this overriding any advancement mode previously set?
For example, if the advancement was media based, are we ok with AUTO_ADVANCE_MEDIA being overriden by ADVANCE_TO?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, actually, good catch. Now that I think of it, I'm not sure ADVANCE_TO is actually an advancement "mode," per se. It would still be a manual advancement, just to the page specified by the advance-to attribute.

But, they already know what page the advancement was to, from the page ID/index. So, I'm not sure knowing that it was because of the advance-to attribute tells them any new information?

Copy link
Contributor

@gmajoulet gmajoulet Jan 25, 2019

Choose a reason for hiding this comment

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

Good point. The new page id and old page id are available, so it'd make sense to keep the "manual", "media based", or "time based" information.

Edit: just realized I'm paraphrasing your comment, sorry about that, it actually took a few minutes to understand all the context

Copy link
Contributor

@gmajoulet gmajoulet left a comment

Choose a reason for hiding this comment

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

targetPage.element.id,
oldPage.element.id,
targetPage.getNextPageId() === null /* isFinalPage */
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Moving this piece of code here changes the behavior of the analytics: now it won't get triggered for the first page, when a user loads the story.
I think we can keep the code where it was before, and just make sure we don't cause any error when oldPage is not defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it & done.

* @param {number} pageIndex
* @param {number} totalPages
* @param {string} pageId
* @param {string} previousPageId
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: previousPageId is nullable, for the first navigation (when the story renders)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: ?string is the shorthand for string|null if you want :))

@bramanudom
Copy link
Contributor Author

Could you please make sure your implementation also works for the desktop pagination buttons (https://github.com/ampproject/amphtml/blob/master/extensions/amp-story/1.0/pagination-buttons.js#L146) and the embedded components (https://github.com/ampproject/amphtml/blob/master/extensions/amp-story/1.0/amp-story-embedded-component.js#L768)?

Manually tested and seems to be working as intended.

Copy link
Contributor

@gmajoulet gmajoulet 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 implementing all the changes :)))

noranazmy pushed a commit to noranazmy/amphtml that referenced this pull request Mar 22, 2019
* WIP adding advacementMode and previousPageId as analytics variables

* WIP: made more changes following the onNavigationState update pattern instead

* moved around some code, got rid of excess

* added tests

* tested with helloworld

* cleaned code

* linted, cleaned more

* got rid of changes to examples, removed unecessary changes

* fixed typo, oops!

* removed analytics trigger, addressed nits

* removed analytics test, added variable service test

* removed advance_to as an advancement mode, capture other instances of manual advancing

* addressed requested changes

* ?string shorthand instead of string|null

* fixed navigation state tests
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.

5 participants