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

✨ Require visibility trigger selector's to have data-vars-* #26902

Merged
merged 6 commits into from
May 1, 2020

Conversation

micajuine-ho
Copy link
Contributor

@micajuine-ho micajuine-ho commented Feb 21, 2020

Task 3 of #26823

  • Filter only elements that have data-vars-* attribute within getAmpElements()

@micajuine-ho
Copy link
Contributor Author

@zhouyx PTAL

extensions/amp-analytics/0.1/analytics-root.js Outdated Show resolved Hide resolved
config = {};

eventsSpy = env.sandbox.spy(tracker, 'onEvent_');

target3 = win.document.createElement('div');
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 see the need to introduce the target3 here? Any reason we want a third element.

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 felt that it was important to test/show that array selector was using querySelectorAll here... but I guess we talked about this before and agreed that this functionality is handled by analytics root and so should be tested there...

Removing now

@micajuine-ho
Copy link
Contributor Author

@zhouyx Ready for review

@@ -300,7 +302,7 @@ export class AnalyticsRoot {
}
for (let j = 0; j < nodeList.length; j++) {
if (this.contains(nodeList[j])) {
elementArray.push(nodeList[j]);
this.checkElementDataVars(nodeList[j], elementArray, selector);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Can we make this a private method.
Personally I would expect the checkElementDataVars to return a boolean based on the method name, and you won't need to pass the elementArray or selector. Not blocking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the method.

if (dataVarKeys.length) {
elementArray.push(element);
} else {
user().warn(
Copy link
Contributor

Choose a reason for hiding this comment

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

When multiple elements are selected. I think the message here will get duplicated.

One option is to also print the element information. A better option is to only print the warning message once with the number of elements that don't have data-vars- attribute specified. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I agree, changed up the method to do slightly more work.

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.

LGTM!

extensions/amp-analytics/0.1/test/test-analytics-root.js Outdated Show resolved Hide resolved
@micajuine-ho micajuine-ho merged commit 5aaea99 into ampproject:master May 1, 2020
@micajuine-ho micajuine-ho deleted the restrict_to_data_vars branch May 5, 2020 18:56
@micajuine-ho micajuine-ho restored the restrict_to_data_vars branch May 5, 2020 18:56
@micajuine-ho micajuine-ho deleted the restrict_to_data_vars branch May 5, 2020 18:56
ldoroshe pushed a commit to ldoroshe/amphtml that referenced this pull request May 8, 2020
…ct#26902)

* Restrict data-vars, impl, unit, manual test

* Adding warning

* Suggested changes
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.

4 participants