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

o-tracking add IntersectionObserver.threshold as opt #1948

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libraries/o-tracking/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ To track when an element has come into view of the user, add the attribute `data
- To track different elements, set the `selector` option property to a CSS selector.
- Like click events, view events will also track the path from the root of the DOM tree to the element which triggered the tracking event into a property called `domPathTokens`.
- To categorise the view events, set the `category` option property.
- To customise the how much of this element needs to be in the viewport to trigger the event, use the `intersectionObserverThreshold` option. This value will be set as the threshold for the IntersectionObserver (it defaults to `1.0`).
- To collect extra data to send with the tracking event, add a function named `getContextData` to the options. The function receives as it's single argument the element which triggered the tracking event and needs to return an object with any of these optional properties set:
- `componentContentId`
- `type`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const decorateEventData = (eventData, viewedEl, opts) => {
* Listen for view events.
*
* @alias view#init
* @param {object} opts - To set custom category[String], selector[String], getContextData[Function]
* @param {object} opts - To set custom category[String], selector[String], getContextData[Function], intersectionObserverThreshold[Any]
* @returns {undefined}
*/
const init = (opts = {}) => {
Expand Down Expand Up @@ -75,7 +75,7 @@ const init = (opts = {}) => {
});
}

const observer = new IntersectionObserver(onChange, { threshold: [ 1.0 ] });
const observer = new IntersectionObserver(onChange, { threshold: opts.intersectionObserverThreshold || [ 1.0 ] });

elementsToTrack.forEach(el => observer.observe(el));
};
Expand Down
Loading