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

Analytics: Refactor EventTracker producers so they are always singletons #11948

Merged
merged 9 commits into from Nov 8, 2017

Conversation

pomeroyr
Copy link
Contributor

@pomeroyr pomeroyr commented Nov 6, 2017

Related to #11813, refactor which allows the dynamic production of EventTrackers inside EventTrackers without producing one-off objects.

@pomeroyr
Copy link
Contributor Author

pomeroyr commented Nov 6, 2017

@zhouyx Ready for review.

Copy link
Contributor

@zhouyx zhouyx left a comment

Choose a reason for hiding this comment

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

Can we also migrate to the getTrackerForOptions in test-events.js
I see places where we create tracker manually. https://github.com/ampproject/amphtml/blob/master/extensions/amp-analytics/0.1/test/test-events.js#L1076

* @param {!Object<string, function(new:./events.EventTracker)>} options
* @return {?./events.EventTracker}
*/
getTrackerForOptions(name, options) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The option here is serving as a klass whitlist. would whitelistKlass be a better name?

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.

*/
getTrackerForOptions(name, options) {
const trackerProfile = options[name];
if (!!trackerProfile) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need !! 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.

Done. It explicitly casts to a boolean value, which if blocks do implicitly, so it's mostly stylistic here.

@@ -450,7 +450,7 @@ export class AnalyticsGroup {
if (!trackerProfile && !isEnumValue(AnalyticsEventType, eventType)) {
trackerProfile = EVENT_TRACKERS['custom'];
}
if (trackerProfile) {
if (!!trackerProfile) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why we need !! here? I believe if (trackerProfile) is good enough.

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.

@@ -142,6 +142,21 @@ export class AnalyticsRoot {
getElementById(unusedId) {}

/**
* Returns the tracker for the specified name and list of allowed types.
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a unit test 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.

Done.

new SUPPORT_WAITFOR_TRACKERS[waitForSpec](this.root);
let waitForTracker = this.waitForTrackers_[waitForSpec];
if (!waitForTracker) {
waitForTracker = this.root.getTrackerForOptions(
Copy link
Contributor

Choose a reason for hiding this comment

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

root.getTrackerForOptions() can return a null, it's safer to check the value before calling waitForTracker.getElementSignal.
I know this should never happen here because we've checked SUPPORT_WAITFOR_TRACKERS[waitForSpec] before. But still. Maybe it would be better to move around the check.

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.

@zhouyx
Copy link
Contributor

zhouyx commented Nov 8, 2017

@pomeroyr just one more request. please see
#11948 (review) Thanks!

@pomeroyr
Copy link
Contributor Author

pomeroyr commented Nov 8, 2017

@zhouyx Done. I chose to just use getTracker since every single use in test expects only one possible result anyway.

@zhouyx
Copy link
Contributor

zhouyx commented Nov 8, 2017

Thanks for the refactor!!

@zhouyx zhouyx merged commit 8389b52 into ampproject:master Nov 8, 2017
neko-fire pushed a commit to 3qnexx/amphtml that referenced this pull request Nov 17, 2017
…ons (ampproject#11948)

* analytics root produces eventtrackers

* test and rename

* fix lint

* force tests

* force tests

* no more one off trackers in test

* force tests

* force tests
gzgogo pushed a commit to gzgogo/amphtml that referenced this pull request Jan 26, 2018
…ons (ampproject#11948)

* analytics root produces eventtrackers

* test and rename

* fix lint

* force tests

* force tests

* no more one off trackers in test

* force tests

* force tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants