✨[amp-analytics] Add Multiple Video Selector Functionality for amp-video#34841
✨[amp-analytics] Add Multiple Video Selector Functionality for amp-video#34841micajuine-ho merged 30 commits intoampproject:mainfrom
Conversation
|
This pull request introduces 1 alert when merging 6bf51b3 into 6efb0c0 - view on LGTM.com new alerts:
|
micajuine-ho
left a comment
There was a problem hiding this comment.
This PR is looking good so far! Left a few notes below.
One thing I think we also need to support is the fact that a selector can map to multiple elements. i.e. the class myVideoClass can be applied to multiple videos, and so if the analytics config has the selector [.myVideoClass], it should find all the elements with the myVideoClass associated. See analytics-root/#getElements().
Next up as well is to add unit tests. We'd normally add tests for this new functionality to their parent tests in test-events.js. However, tests-events does not have any tests for VideoEventTracker. So instead, I propose that we create a new tests-video-event-tracker.js file and test our new functionality. The tests will include having a fake config and initializing a VideoEventTracker for each trigger, then firing fake VideoAnalyticsEvents and letting the sessionObservable handle the rest (and test the rest as well).
…ti-vid-selector
micajuine-ho
left a comment
There was a problem hiding this comment.
Looking really good! Just a few asks
There was a problem hiding this comment.
Nice work on your first PR!
The most important change to make before approval is using a single getElements() result of target[] rather than target[][]. See my corresponding comment.
alanorozco
left a comment
There was a problem hiding this comment.
Nice work!
I'm approving, but also requesting to remove documentation changes before merging to handle them separately.
micajuine-ho
left a comment
There was a problem hiding this comment.
Approving, with the 1 request. And I agree that we should move the documentation to a separate PR
This reverts commit 9773abc.
|
Notes from our 1-1:
|
| * @return {!Promise<!Array<!Element>>} Element corresponding to the selector. | ||
| */ | ||
| getElementsByQuerySelectorAll_(selectors) { | ||
| getElementsByQuerySelectorAll_(selectors, useDataVars) { |
There was a problem hiding this comment.
Please add jsDoc for this new parameter.
micajuine-ho
left a comment
There was a problem hiding this comment.
Really great work! Two asks and then we can merge!
|
Wooohoo!! |
|
Thank everyone! I just wanted to check when these changes are expected to go live approximately? I was trying to refer to this document for understanding how this works: https://amp.dev/documentation/guides-and-tutorials/learn/spec/release-schedule/ but still not getting a clear picture. Looking forward to be able to use a single CSS selector to target all |
|
They will go live in aprox 2 weeks. Yes, @kalemuw can you provide an example of what that would look like? |
Hey @prathamesh-gharat. Here's a sample config that tracks multiple video elements at once. |
|
Thanks @kalemuw. I have a question. |
@prathamesh-gharat |
|
@kalemuw, is it possible to access the Need to pass the information to GA based on the video being played. I already tried finding on following two links but couldn't anything that worked. Update: Going to copy |
This PR allows the ability to track multiple videos in one configuration. Added in response to #30860.
Previously, to apply the same video trigger configuration to multiple video elements, the same trigger would be duplicated for each video. However, with the edits in this PR, an array of selectors can be specified in the selector argument to apply and track the video trigger on said videos.
Thus, both selectors in form of an array of query selectors and a single query selector string are supported in the configuration and are tracked.
Edits
events.js- Add a condition to treat every selector passed as an array
- Parse each selector from the array passed in and get the elements. Note: this is conditioned that the video elements do not have data-var-
- Add event unlisteners
amp-video-multiple-selectors.amp.html- Add test with two videos.
- Add test cases for VideoTracker class in events.js
analytics-root.js- Add boolean useDataVars to condition getElements() function call to getDataVarsElement_() function.
test-analytics-root.js- Add test to check the data-vars-* conditionality
Reviewer: @micajuine-ho , @alanorozco