-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Backgrounded Variable added to Timer Trigger #5240
Merged
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
019e5fc
Added backgrounded variable to timer trigger.
dynes 0d50d02
Merge branch 'master' of ssh://github.com/ampproject/amphtml into vie…
dynes 8284e88
Merge branch 'master' of ssh://github.com/ampproject/amphtml into vie…
dynes e8799de
Inlined backgrounded field in vars object.
dynes ac17bf0
Merge branch 'master' of ssh://github.com/ampproject/amphtml into vie…
dynes 12c2187
Hoisted timer event function.
dynes 329663a
Merge branch 'master' of ssh://github.com/ampproject/amphtml into vie…
dynes ec024b3
Merge branch 'master' of ssh://github.com/ampproject/amphtml into vie…
dynes e92bba9
Added BACKGROUNDED_STATE to url replacements. Added support for BACK…
dynes d8591f3
Use correct set call for BACKGROUNDED_STATE call.
dynes 3dab5b2
Changed BACKGROUNDED_STATE to BACKGROUND_STATE
dynes 33c59b3
Update instrumentation.js
avimehta File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -492,13 +492,17 @@ export class InstrumentationService { | |
createTimerListener_(listener, timerSpec) { | ||
const hasImmediate = timerSpec.hasOwnProperty('immediate'); | ||
const callImmediate = hasImmediate ? Boolean(timerSpec.immediate) : true; | ||
const intervalId = this.win_.setInterval( | ||
listener.bind(null, new AnalyticsEvent(AnalyticsEventType.TIMER)), | ||
timerSpec['interval'] * 1000 | ||
); | ||
const viewer = this.viewer_; | ||
const intervalId = this.win_.setInterval(() => { | ||
const vars = {}; | ||
vars['backgrounded'] = viewer.isVisible() ? '0' : '1'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be done inline: const vars = {
backgrounded: viewer.isVisible ? '0' : '1',
}; |
||
listener(new AnalyticsEvent(AnalyticsEventType.TIMER, vars)); | ||
}, timerSpec['interval'] * 1000); | ||
|
||
if (callImmediate) { | ||
listener(new AnalyticsEvent(AnalyticsEventType.TIMER)); | ||
const vars = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could instead call the function above directly. |
||
vars['backgrounded'] = viewer.isVisible() ? '0' : '1'; | ||
listener(new AnalyticsEvent(AnalyticsEventType.TIMER, vars)); | ||
} | ||
|
||
const maxTimerLength = timerSpec['maxTimerLength'] || | ||
|
@@ -516,3 +520,4 @@ export function instrumentationServiceFor(window) { | |
return fromClass(window, 'amp-analytics-instrumentation', | ||
InstrumentationService); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's hoist this function instead of passing it. Then we can call it in the
callImmediate
conditional below.