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

Backgrounded Variable added to Timer Trigger #5240

Merged
merged 12 commits into from Oct 6, 2016

Conversation

dynes
Copy link
Contributor

@dynes dynes commented Sep 26, 2016

Allows timer endpoints access to backgrounded variable.

Fixes #4844.

@dynes
Copy link
Contributor Author

dynes commented Sep 26, 2016

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?

@jridgewell
Copy link
Contributor

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';
Copy link
Contributor

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 = {};
Copy link
Contributor

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(() => {
Copy link
Contributor

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.

@jridgewell
Copy link
Contributor

@avimehta: Please confirm this is all that's needed for #4844.

…wer-background

Conflicts:
	extensions/amp-analytics/0.1/instrumentation.js
@dynes
Copy link
Contributor Author

dynes commented Sep 30, 2016

@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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm?

Copy link
Contributor Author

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.

Copy link
Contributor

@jridgewell jridgewell left a 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.

@dynes
Copy link
Contributor Author

dynes commented Oct 4, 2016

@avimehta Any changes that you would recommend, or does this satisfy the original issue #4844 ?

@avimehta
Copy link
Contributor

avimehta commented Oct 5, 2016

@rudygalfi This changes the meaning of backgrounded variable depending on whether the trigger is visible or timer. I think that is not desirable. wdyt?

@avimehta
Copy link
Contributor

avimehta commented Oct 5, 2016

Talked to @rudygalfi offline. Here are a few changes we'll need to make:

  • Rename the variable to backgroundState.
  • Instead of having this variable just for timer event, let's make it a platform level variable. so you'll need to edit url-replacements-impl.js
  • Add documentation for this in amp-analytics documentation and variable-spec. (I am working on combining the two docs but that is not read yet so you'll have to edit both the files.)
  • Add tests for this in url-replacements-test.js

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.
@dynes
Copy link
Contributor Author

dynes commented Oct 6, 2016

Looks like there is an extra build step that is not in the documentation.

gulp check-types

Will be committing changes soon.

@dynes
Copy link
Contributor Author

dynes commented Oct 6, 2016

@avimehta My changes should satisfy the concerns/requests that you brought up. Let me know if any further changes are required.

@dynes
Copy link
Contributor Author

dynes commented Oct 6, 2016

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() {
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 these changes can be reverted. no?

Copy link
Contributor

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',
Copy link
Contributor

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.

Copy link
Contributor

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.

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 did in the last commit added.

Copy link
Contributor

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.

@googlebot
Copy link

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.

@avimehta
Copy link
Contributor

avimehta commented Oct 6, 2016

Your PR is good to go. Will merge as soon as tests pass.

@jridgewell
Copy link
Contributor

@avimehta: You'll need to tell CLA Bot that you accept the CLA. :sigh:

@avimehta
Copy link
Contributor

avimehta commented Oct 6, 2016

@googlebot I really do accept the CLA :)

@dynes
Copy link
Contributor Author

dynes commented Oct 6, 2016

@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?

@superbaddude
Copy link
Contributor

@googlebot I accept the CLA.

@jridgewell
Copy link
Contributor

@dynes an @avimehta are the only one's that need to approve. However, you need to commit with the same email address that you signed the CLA with.

@dynes
Copy link
Contributor Author

dynes commented Oct 6, 2016

@googlebot I accept the CLA.

@avimehta
Copy link
Contributor

avimehta commented Oct 6, 2016

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.

@erwinmombay erwinmombay merged commit 784d268 into ampproject:master Oct 6, 2016
samiamorwas pushed a commit to samiamorwas/amphtml that referenced this pull request Oct 10, 2016
…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)
  ...
dreamofabear pushed a commit to dreamofabear/amphtml that referenced this pull request Oct 12, 2016
* 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
mkhatib pushed a commit to mkhatib/amphtml that referenced this pull request Oct 14, 2016
* 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
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