Commit 02efffc0 by James Ooi

Make config parameter optional

parent 41505fa1
......@@ -22,10 +22,10 @@ interface ForesightConfig {
/** Configure the intersection observer. */
observerOptions?: IntersectionObserverInit
/** Treat clicks as an interactive event. Defaults to true. */
/** Treat clicks as an interactive event. Defaults to `true`. */
clicksAreInteractions?: boolean
/** Treat views as an interactive event. Defaults to false. */
/** Treat views as an interactive event. Defaults to `false`. */
viewsAreInteractions?: boolean
}
......@@ -53,9 +53,9 @@ class Foresight {
*/
static defaultOptions: Partial<ForesightConfig> = {
defer: false,
observerOptions: {},
clicksAreInteractions: true,
viewsAreInteractions: false,
observerOptions: {},
}
/**
......@@ -80,7 +80,7 @@ class Foresight {
/**
* @constructor
*/
constructor(config: ForesightConfig) {
constructor(config: ForesightConfig = {}) {
this.options = { ...Foresight.defaultOptions, ...config };
// Initialise IntersectionObserver
......@@ -100,7 +100,8 @@ class Foresight {
}
/**
* Start event tracking for all DOM elements with event tracking attributes.
* Start tracking all elements with tracking attributes for events.
* @param {Element} root The container to scan for elements. Defaults to `body`.
*/
start(root: Element = document.body) {
if (gtag === undefined) {
......@@ -113,7 +114,7 @@ class Foresight {
}
/**
* Enables event tracking for a DOM element with event tracking attribute.
* Start tracking an element for events.
*/
track(element: Element) {
if (!this._untrackFns.has(element)) {
......@@ -140,7 +141,7 @@ class Foresight {
}
/**
* Disable event tracking for a DOM element.
* Stop tracking an element for events.
*/
untrack(element: Element) {
const untrackFn = this._untrackFns.get(element);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment