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

Add Activity service to calculate engaged time for amp-analytics #1818

Merged
merged 1 commit into from Feb 22, 2016

Conversation

britice
Copy link

@britice britice commented Feb 5, 2016

Add new Activity service which can be used to track general user interaction on a page over time.

The first goal of adding this service is to provide active engaged time heuristics for url replacement in amp-analytics. This will address issue #1296.

In order to collect active engaged time heuristics, user activity will need to be collected during the session. Given that user activity will be collected, there is a chance that the Activity service will also be able to expose additional data about general user interaction beyond total engaged time.

@britice
Copy link
Author

britice commented Feb 5, 2016

So far the Activity service is only providing a stubbed value for the TOTAL_ENGAGED_TIME url replacement.

Similar to the CID service, the Activity service is not installed in amp-core-services.js. Instead, it is installed in amp-analytics.js.

Let me know if there are suggestions, especially concerning:

  • The general pattern being used to provide engaged time.
  • Installing the Activity service in amp-analytics.js rather than as a core service.

@cramforce
Copy link
Member

  • @avimehta
    Will take a look later. From a glance at the files more tests would be appreciated :)

@britice
Copy link
Author

britice commented Feb 5, 2016

From a glance at the files more tests would be appreciated :)

Definitely understood. This PR is still a work in progress. I included at least the one test to demonstrate how the service is used.

### TOTAL_ENGAGED_TIME

Get the total time the user has been enagaged with the page since the page was
loaded.
Copy link
Contributor

Choose a reason for hiding this comment

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

Loaded, or became visible?

Might be good to be specific here.

cc @cramforce @avimehta for feedback on this.

Copy link

Choose a reason for hiding this comment

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

Become visible in the current viewport I think is the more accepted definition

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, lets change this to "become visible in the viewport"

@rudygalfi
Copy link
Contributor

This looks like a reasonable start.

Regarding whether the Activity service should be in amp-analytics or core: I can definitely imagine this being relevant to other areas. Perf and ads come to mind, but those are entirely hypothetical from my vantage point. @cramforce do you have any take on this? Is starting in amp-analytics and refactoring to core later an option?

@etlgfx
Copy link

etlgfx commented Feb 9, 2016

I'd love to help you guys out with this if you guys think that would be useful?

@britice
Copy link
Author

britice commented Feb 9, 2016

I'd love to help you guys out with this if you guys think that would be useful?

Thanks @etlgfx. I'm working to get another commit out tonight or early tomorrow which contains the core functionality for the Activity service. Once I get that out, I'm sure there will be some additional feedback needed.

As was mentioned earlier, I need to take care of testing for this feature. Any input there would be greatly appreciated (e.g. what to test, where to test, how to ensure good test coverage).

@britice
Copy link
Author

britice commented Feb 11, 2016

I pushed a new commit which fleshes out the total engaged time functionality.

This went through several iterations before landing on only tracking total engaged time. In one version, all activity times were recorded (with 1 second resolution). This would have allowed for finding engaged time for an arbitrary time period but would require either recalculation of engaged time on each getTotalEngagedTime request or a more complex data structure which stored previous calculations of engaged time intervals. In the end, I opted for a simpler approach which could gather the most important metric with the lowest potential impact on performance.

There is still more to do and I'd appreciate feedback on the functionality. In the mean time, I'll start working on tests before adding other activity listeners.

@rudygalfi
Copy link
Contributor

cc @msukmanowsky

@britice
Copy link
Author

britice commented Feb 16, 2016

@avimehta @cramforce I added another commit which includes functional tests for the Activity service. It also includes changes which account for user "inactivity" events.

@britice
Copy link
Author

britice commented Feb 17, 2016

Brought things up to date with master.

@britice
Copy link
Author

britice commented Feb 18, 2016

@avimehta @cramforce After the Travis check is complete, this PR is ready for review.

Get the total time the user has been enagaged with the page since the page was
loaded.

For instance:
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we don't need this example here, since that would always be zero.

@britice
Copy link
Author

britice commented Feb 19, 2016

Ready for another pass. All PR comments are addressed in the first new commit. There were a few other minor changes in the second two commits. I'm planning to squash everything into one commit when we are satisfied with the updates. If it is preferred that I squash prior to another review, let me know.

@britice britice closed this Feb 19, 2016
@britice britice reopened this Feb 19, 2016
@britice
Copy link
Author

britice commented Feb 19, 2016

Ooops, hit "Close and Comment" instead of "comment".

@rudygalfi
Copy link
Contributor

@britice It seems like this is feature complete? Can you confirm?

@britice
Copy link
Author

britice commented Feb 19, 2016

It seems like this is feature complete? Can you confirm?

Yes, this is complete.

@cramforce
Copy link
Member

Please disallow unwhitelisted usage of installActivityService in presubmit-checks.js.

Would be great if @avimehta could take a look!

@avimehta
Copy link
Contributor

looking at it now. will respond in a couple of hours.

this.unlistenFuncs_ = [];
}

cleanup_() {
Copy link
Contributor

Choose a reason for hiding this comment

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

curious about how this gets called. Also, docs for this?

Copy link
Author

Choose a reason for hiding this comment

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

It's not being called at this point. I saw cleanup_ functionality in other components and decided to set this up here as well. Since the activity tracking is intended to be available until the user leaves the page, it didn't seem necessary to ensure it was called anywhere.

I'll add the annotations for all the methods.

@avimehta
Copy link
Contributor

@cramforce overall the PR looks good to me. Since I am not an expert at the platform stuff, I'll defer to your lgtm.

* @param {!Window} window
* @return {!Promise<?Activity>}
*/
export function activityForOrNull(win) {
Copy link
Member

Choose a reason for hiding this comment

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

You can delete this as it is never used.

@cramforce
Copy link
Member

LGTM. One comment. Please also squash commits.

@britice
Copy link
Author

britice commented Feb 19, 2016

Added another commit to address a few more PR comments. I'll squash and force push momentarily.

@britice
Copy link
Author

britice commented Feb 19, 2016

This is ready when checks pass.

@britice
Copy link
Author

britice commented Feb 19, 2016

Looks like this has gotten fairly far behind master. Let me know if I should rebase prior to merging.

@emmettbutler
Copy link

This method of tracking engagement is a bit different from what we're doing at Parse.ly, but it all makes sense to me.

@rudygalfi
Copy link
Contributor

@emmett9001 Thanks for taking a look! Do you think Parsely would be able to use this implementation for AMP? Main goal is to make sure we have an implementation that's reasonable and works for all.

Would you be good with merging this (and we can enhance further in the future)?

@britice
Copy link
Author

britice commented Feb 22, 2016

I brought this up to date with master.

@rudygalfi @emmett9001 Is there any other input from Parsley that needs to be considered before this is merged?

A previous update to Chartbeat's vendor config (#1986) is somewhat dependent on this PR so we'd like to see them combined for the next release.

@emmettbutler
Copy link

@britice @rudygalfi This looks close enough to what Pasre.ly's currently doing that I think it's fine to merge. There may be some small changes I'm not noticing now that come up later, but I don't think any of them will require a major rewrite.

rudygalfi added a commit that referenced this pull request Feb 22, 2016
Add Activity service to calculate engaged time for amp-analytics
@rudygalfi rudygalfi merged commit 388a3d6 into ampproject:master Feb 22, 2016
@britice britice deleted the engaged-time branch February 22, 2016 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants