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

Added support for a new trigger on=hidden. #4265

Merged
merged 2 commits into from Aug 8, 2016

Conversation

avimehta
Copy link
Contributor

The new trigger fires when the viewer is hidden. In addition,
visibilitySpec can be used to add additional conditions on when the
trigger fires.

Fixes #2487 #2564

- `selector` This property can be used to specify the element to which all the `visibilitySpec` conditions apply. The selector needs to be an css id that points to an [AMP extended element](https://github.com/ampproject/amphtml/blob/master/spec/amp-tag-addendum.md#amp-specific-tags).
- `continuousTimeMin` and `continuousTimeMax` These properties indicate that a request should be fired when (any part of) an element has been within the viewport for a continuous amount of time that is between the minimum and maximum specified times. The times are expressed in milliseconds. Due to semantic restrictions, `continuousTimeMax` only works when the page is being hidden. Hence `continuousTimeMax` is not yet supported.
- `totalTimeMin` and `totalTimeMax` These properties indicate that a request should be fired when (any part of) an element has been within the viewport for a total amount of time that is between the minimum and maximum specified times. The times are expressed in milliseconds. Due to semantic restrictions, `totalTimeMax` only works when the page is being hidden. Hence `totalTimeMax` is not yet supported.
- `continuousTimeMin` and `continuousTimeMax` These properties indicate that a request should be fired when (any part of) an element has been within the viewport for a continuous amount of time that is between the minimum and maximum specified times. The times are expressed in milliseconds.
Copy link
Contributor

Choose a reason for hiding this comment

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

The Max vars are the ones that are only valid for hidden, right?

Can you note that 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.

I thought about it a bit more and I think a condition like the following should be valid. that is the reason I removed the text that mentioned that *max conditions are not valid for "on"="visible"

Send a hit if the element is visible at least for 5 seconds but not for more than 1 second at a time.

"continuousTimeMax": 1000,
"totalTimeMin": 5000

Send a hit if the element is visible for not more than 5 seconds in total but at least visible for 1 second continuously.

"continuousTimeMin": 1000,
"totalTimeMax": 5000

ps: I think the examples above are a bit made-up and may not be realistic but let's not limit the usage because we can't think of a use-case right now.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, makes sense, thanks

@rudygalfi
Copy link
Contributor

Just one small comment, but docs overall LGTM

@avimehta
Copy link
Contributor Author

avimehta commented Aug 1, 2016

@dvoytenko Do you mind reviewing this PR?

@@ -128,7 +129,7 @@ export class InstrumentationService {
addListener(config, listener) {
const eventType = config['on'];
if (eventType === AnalyticsEventType.VISIBLE) {
this.createVisibilityListener_(listener, config);
this.createVisibilityListener_(listener, config, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add /* arg */ true

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.

@dvoytenko
Copy link
Contributor

@avimehta Generally things look alright. One thing is that the use of non-throttled scroll listener here might be pretty expensive. I'm cc-ing @jridgewell from the initial review. Is the non-throttled scroll listener absolutely necessary here? Did we debug the performance of this?

@avimehta
Copy link
Contributor Author

avimehta commented Aug 3, 2016

rebased and Fixed #4361. ptal.

@@ -131,7 +132,7 @@ export class InstrumentationService {
addListener(config, listener) {
const eventType = config['on'];
if (eventType === AnalyticsEventType.VISIBLE) {
this.createVisibilityListener_(listener, config);
this.createVisibilityListener_(listener, config, /* visible */ true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not pass in AnalyticsEventType.VISIBLE or HIDDEN?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that can be done. Will update the PR. (no negatives I can think of)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated the PR. I did not change visibility-impl to also accept the eventType because it didn't make a whole lot of sense. I did update the names and description to clarify what the code is trying to do.

@dvoytenko
Copy link
Contributor

LGTM

@avimehta
Copy link
Contributor Author

avimehta commented Aug 8, 2016

@dvoytenko Thanks for the review here. I'll need to resolve conflicts with #4072 and then I'll merge.

Regarding your our comment about performance of the scroll events, I am open to switching to batched events if performance becomes an issue. Most of the calculations on each scroll have been a few of counter updates and if-else blocks so far.

The new trigger fires when the viewer is hidden. In addition,
visibilitySpec can be used to add additional conditions on when the
trigger fires.
@avimehta avimehta merged commit 572c687 into ampproject:master Aug 8, 2016
@avimehta avimehta deleted the unload branch August 8, 2016 22:31
ariangibson pushed a commit to Mixpo/amphtml that referenced this pull request Sep 7, 2016
* Added support for a new trigger `on=hidden`.

The new trigger fires when the viewer is hidden. In addition,
visibilitySpec can be used to add additional conditions on when the
trigger fires.

* variable rename.
mityaha pushed a commit to ooyala/amphtml that referenced this pull request Nov 30, 2016
* Added support for a new trigger `on=hidden`.

The new trigger fires when the viewer is hidden. In addition,
visibilitySpec can be used to add additional conditions on when the
trigger fires.

* variable rename.
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.

None yet

4 participants