Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
foresight
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
libraries
foresight
Commits
48b6bcaa
Commit
48b6bcaa
authored
Aug 02, 2018
by
James Ooi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement auto track on initialisation
parent
ba4e3ef3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
10 deletions
+21
-10
foresight.ts
src/foresight.ts
+21
-8
tsconfig.json
tsconfig.json
+0
-1
tsconfig.prod.json
tsconfig.prod.json
+0
-1
No files found.
src/foresight.ts
View file @
48b6bcaa
/*
*
/*
!
* Foresight
*
* @author James Ooi <james.ooi@forefront.com.my>
...
...
@@ -16,11 +16,18 @@ declare var gtag: (action: string, ...args: any[]) => any;
* Available options for configuring Foresight.
*/
interface
ForesightConfig
{
/** Defer tracking initialisation. */
defer
?:
boolean
/** Configure the intersection observer. */
observerOptions
?:
IntersectionObserverInit
nonInteractionClicks
?:
boolean
nonInteractionViews
?:
boolean
}
/** Treat clicks as an interactive event. Defaults to true. */
clicksAreInteractions
?:
boolean
/** Treat views as an interactive event. Defaults to false. */
viewsAreInteractions
?:
boolean
}
/**
* Represents a particular event's data.
...
...
@@ -45,8 +52,9 @@ class Foresight {
* @static
*/
static
defaultOptions
:
Partial
<
ForesightConfig
>
=
{
nonInteractionClicks
:
false
,
nonInteractionViews
:
true
,
defer
:
false
,
clicksAreInteractions
:
true
,
viewsAreInteractions
:
false
,
observerOptions
:
{},
}
...
...
@@ -84,6 +92,11 @@ class Foresight {
}
});
},
this
.
options
.
observerOptions
);
// Start tracking
if
(
!
this
.
options
.
defer
)
{
this
.
start
();
}
}
/**
...
...
@@ -211,7 +224,7 @@ class Foresight {
const
s
=
element
.
getAttribute
(
'data-track'
);
const
data
=
this
.
_parseEventString
(
s
);
data
.
interaction
=
!
this
.
options
.
nonInteractionClick
s
;
data
.
interaction
=
this
.
options
.
clicksAreInteraction
s
;
if
(
element
.
getAttribute
(
'data-track:non-interaction'
)
!==
null
)
{
data
.
interaction
=
false
;
}
...
...
@@ -231,7 +244,7 @@ class Foresight {
const
s
=
element
.
getAttribute
(
'data-track-view'
);
const
data
=
this
.
_parseEventString
(
s
);
data
.
interaction
=
!
this
.
options
.
nonInteractionView
s
;
data
.
interaction
=
this
.
options
.
viewsAreInteraction
s
;
if
(
element
.
getAttribute
(
'data-track-view:interaction'
)
!==
null
)
{
data
.
interaction
=
true
;
}
...
...
tsconfig.json
View file @
48b6bcaa
...
...
@@ -3,7 +3,6 @@
"target"
:
"es5"
,
"allowJs"
:
false
,
"noImplicitAny"
:
false
,
"removeComments"
:
true
,
"lib"
:
[
"es6"
,
"dom"
]
},
"exclude"
:
[
...
...
tsconfig.prod.json
View file @
48b6bcaa
...
...
@@ -5,7 +5,6 @@
"declarationDir"
:
"./typings"
,
"allowJs"
:
false
,
"noImplicitAny"
:
false
,
"removeComments"
:
true
,
"lib"
:
[
"es6"
,
"dom"
]
},
"exclude"
:
[
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment