Commit 02efffc0 by James Ooi

Make config parameter optional

parent 41505fa1
...@@ -22,10 +22,10 @@ interface ForesightConfig { ...@@ -22,10 +22,10 @@ interface ForesightConfig {
/** Configure the intersection observer. */ /** Configure the intersection observer. */
observerOptions?: IntersectionObserverInit observerOptions?: IntersectionObserverInit
/** Treat clicks as an interactive event. Defaults to true. */ /** Treat clicks as an interactive event. Defaults to `true`. */
clicksAreInteractions?: boolean clicksAreInteractions?: boolean
/** Treat views as an interactive event. Defaults to false. */ /** Treat views as an interactive event. Defaults to `false`. */
viewsAreInteractions?: boolean viewsAreInteractions?: boolean
} }
...@@ -53,9 +53,9 @@ class Foresight { ...@@ -53,9 +53,9 @@ class Foresight {
*/ */
static defaultOptions: Partial<ForesightConfig> = { static defaultOptions: Partial<ForesightConfig> = {
defer: false, defer: false,
observerOptions: {},
clicksAreInteractions: true, clicksAreInteractions: true,
viewsAreInteractions: false, viewsAreInteractions: false,
observerOptions: {},
} }
/** /**
...@@ -80,7 +80,7 @@ class Foresight { ...@@ -80,7 +80,7 @@ class Foresight {
/** /**
* @constructor * @constructor
*/ */
constructor(config: ForesightConfig) { constructor(config: ForesightConfig = {}) {
this.options = { ...Foresight.defaultOptions, ...config }; this.options = { ...Foresight.defaultOptions, ...config };
// Initialise IntersectionObserver // Initialise IntersectionObserver
...@@ -100,7 +100,8 @@ class Foresight { ...@@ -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) { start(root: Element = document.body) {
if (gtag === undefined) { if (gtag === undefined) {
...@@ -113,7 +114,7 @@ class Foresight { ...@@ -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) { track(element: Element) {
if (!this._untrackFns.has(element)) { if (!this._untrackFns.has(element)) {
...@@ -140,7 +141,7 @@ class Foresight { ...@@ -140,7 +141,7 @@ class Foresight {
} }
/** /**
* Disable event tracking for a DOM element. * Stop tracking an element for events.
*/ */
untrack(element: Element) { untrack(element: Element) {
const untrackFn = this._untrackFns.get(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