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
Conversation
…wer-background Conflicts: extensions/amp-analytics/0.1/instrumentation.js
I have not touched amp-analytics.visibility, and I cannot get those tests to fail locally. I have ran gulp test multiple times and cannot get those tests to fail. I'm not sure what the appropriate next step is here? |
We have some known test flake. I've restarted the travis build. |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done inline:
const vars = {
backgrounded: viewer.isVisible ? '0' : '1',
};
|
||
if (callImmediate) { | ||
listener(new AnalyticsEvent(AnalyticsEventType.TIMER)); | ||
const vars = {}; |
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.
We could instead call the function above directly.
timerSpec['interval'] * 1000 | ||
); | ||
const viewer = this.viewer_; | ||
const intervalId = this.win_.setInterval(() => { |
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.
…wer-background Conflicts: extensions/amp-analytics/0.1/instrumentation.js
@jridgewell Hoisted function. Let me know if that's what you were looking for. |
@@ -496,16 +496,17 @@ export class InstrumentationService { | |||
*/ | |||
createTimerListener_(listener, timerSpec) { | |||
const hasImmediate = timerSpec.hasOwnProperty('immediate'); | |||
const callImmediate = hasImmediate ? Boolean(timerSpec.immediate) : true; | |||
const callImmediate = hasImmediate ? Boolean(timerSpec['immediate']) : true; |
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.
Hm?
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.
That was a merged in change.
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.
Yup, that's it. Pending @avimehta's review.
@rudygalfi This changes the meaning of |
Talked to @rudygalfi offline. Here are a few changes we'll need to make:
Finally, apologies for not responding for almost a week. I'll try to move things faster going forward. |
…ROUNDED_STATE in amp-analytics. Added documentation for BACKGROUNDED_STATE. Added tests for BACKGROUNDED_STATE.
Looks like there is an extra build step that is not in the documentation.
Will be committing changes soon. |
@avimehta My changes should satisfy the concerns/requests that you brought up. Let me know if any further changes are required. |
Small mistake with the naming of the variable. Changed it to the appropriate name of BACKGROUND_STATE instead of BACKGROUNDED_STATE. |
listener.bind(null, new AnalyticsEvent(AnalyticsEventType.TIMER)), | ||
timerSpec['interval'] * 1000 | ||
); | ||
const timerEventFunction = function() { |
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.
I think these changes can be reverted. no?
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.
Reverted these changes.
@@ -30,6 +30,7 @@ export const ANALYTICS_CONFIG = /** @type {!JSONType} */ ({ | |||
'authdata': 'AUTHDATA', | |||
'availableScreenHeight': 'AVAILABLE_SCREEN_HEIGHT', | |||
'availableScreenWidth': 'AVAILABLE_SCREEN_WIDTH', | |||
'backgroundedState': 'BACKGROUNDED_STATE', |
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.
sorry about this being nitpicky. Can you change it to backgroundState and BACKGROUND_STATE. The difference being that past tense variables go from 0 to 1 only once and then never change. The present tense variable gives the current state and can change value either way.
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.
Once you make the change, you'll have to update the docs/examples.
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.
I did in the last commit added.
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.
ah. I was looking at wrong commit then. Let me look again.
We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm. |
Your PR is good to go. Will merge as soon as tests pass. |
@avimehta: You'll need to tell CLA Bot that you accept the CLA. :sigh: |
@googlebot I really do accept the CLA :) |
@superbaddude is the original CLA signer. Will he need to always approve the PR's, or is there a way for me to be added as a approved author? |
@googlebot I accept the CLA. |
@googlebot I accept the CLA. |
It's a problem with my CLA. I had email privacy feature turned on which causes this problem. Talked to @erwinmombay and He'll force merge once the tests pass. |
…mp_reddit_extension * 'master' of https://github.com/ampproject/amphtml: (65 commits) Send vars from carousel to amp-analytics (ampproject#5388) Rolling back pan-x on scrollable carousel. (ampproject#5490) Add context.library.name to Segment (ampproject#5467) Rollback pan-x on carousel as it does not work on android. (ampproject#5473) cron job from @erwinmombay to update size.txt (ampproject#5468) Added example of usage of carousel arrows (ampproject#5397) ALP for A4A (ampproject#5430) Add Affiliate-B support for amp-ad (ampproject#5223) First cut of changes for New Type Inference (ampproject#5438) Lightbox 2.0: Use object-fit:cover for thumbnails Upgrade Closure Compiler to v20160911 (Sep 11, 2016) (ampproject#5457) Fake and real window fixtures for tests (ampproject#5425) Backgrounded Variable added to Timer Trigger (ampproject#5240) make `touch-action: pan-x` on `amp-carousel` (ampproject#5391) Fix PR check on new branches (ampproject#5455) Do not rely on ampExtendedElements being created (ampproject#5454) Turn type checking for 3p code back on. (ampproject#5452) Update ads/README.md with gulp lint tip (ampproject#5444) Migrate document-submit to doc scope (ampproject#5437) Link to Building an AMP Extension document. (ampproject#5451) ...
* Added backgrounded variable to timer trigger. * Inlined backgrounded field in vars object. * Hoisted timer event function. * Added BACKGROUNDED_STATE to url replacements. Added support for BACKGROUNDED_STATE in amp-analytics. Added documentation for BACKGROUNDED_STATE. Added tests for BACKGROUNDED_STATE. * Use correct set call for BACKGROUNDED_STATE call. * Changed BACKGROUNDED_STATE to BACKGROUND_STATE * Update instrumentation.js
* Added backgrounded variable to timer trigger. * Inlined backgrounded field in vars object. * Hoisted timer event function. * Added BACKGROUNDED_STATE to url replacements. Added support for BACKGROUNDED_STATE in amp-analytics. Added documentation for BACKGROUNDED_STATE. Added tests for BACKGROUNDED_STATE. * Use correct set call for BACKGROUNDED_STATE call. * Changed BACKGROUNDED_STATE to BACKGROUND_STATE * Update instrumentation.js
Allows timer endpoints access to backgrounded variable.
Fixes #4844.