@phantomstudios/ft-lib 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/.babelrc +6 -0
  2. package/.eslintrc +58 -0
  3. package/.github/CODEOWNERS +1 -0
  4. package/.github/workflows/pr.yml +31 -0
  5. package/.github/workflows/release.yml +44 -0
  6. package/.nvmrc +1 -0
  7. package/.prettierignore +5 -0
  8. package/CODE_OF_CONDUCT.md +76 -0
  9. package/CONTRIBUTING.md +48 -0
  10. package/LICENSE +21 -0
  11. package/README.md +158 -0
  12. package/SUPPORT.md +4 -0
  13. package/jest.config.js +24 -0
  14. package/lib/FTTracking/index.d.ts +24 -0
  15. package/lib/FTTracking/index.d.ts.map +1 -0
  16. package/lib/FTTracking/index.js +69 -0
  17. package/lib/FTTracking/index.js.map +1 -0
  18. package/lib/consentMonitor/index.d.ts +19 -0
  19. package/lib/consentMonitor/index.d.ts.map +1 -0
  20. package/lib/consentMonitor/index.js +117 -0
  21. package/lib/consentMonitor/index.js.map +1 -0
  22. package/lib/gaTracker/index.d.ts +13 -0
  23. package/lib/gaTracker/index.d.ts.map +1 -0
  24. package/lib/gaTracker/index.js +120 -0
  25. package/lib/gaTracker/index.js.map +1 -0
  26. package/lib/index.d.ts +9 -0
  27. package/lib/index.d.ts.map +1 -0
  28. package/lib/index.js +18 -0
  29. package/lib/index.js.map +1 -0
  30. package/lib/oTracker/index.d.ts +14 -0
  31. package/lib/oTracker/index.d.ts.map +1 -0
  32. package/lib/oTracker/index.js +114 -0
  33. package/lib/oTracker/index.js.map +1 -0
  34. package/lib/permutiveVideoUtils/index.d.ts +12 -0
  35. package/lib/permutiveVideoUtils/index.d.ts.map +1 -0
  36. package/lib/permutiveVideoUtils/index.js +59 -0
  37. package/lib/permutiveVideoUtils/index.js.map +1 -0
  38. package/lib/reactPlayerTracking/index.d.ts +30 -0
  39. package/lib/reactPlayerTracking/index.d.ts.map +1 -0
  40. package/lib/reactPlayerTracking/index.js +85 -0
  41. package/lib/reactPlayerTracking/index.js.map +1 -0
  42. package/lib/utils/attention.d.ts +20 -0
  43. package/lib/utils/attention.d.ts.map +1 -0
  44. package/lib/utils/attention.js +142 -0
  45. package/lib/utils/attention.js.map +1 -0
  46. package/lib/utils/cookies.d.ts +2 -0
  47. package/lib/utils/cookies.d.ts.map +1 -0
  48. package/lib/utils/cookies.js +14 -0
  49. package/lib/utils/cookies.js.map +1 -0
  50. package/lib/utils/getTrace.d.ts +6 -0
  51. package/lib/utils/getTrace.d.ts.map +1 -0
  52. package/lib/utils/getTrace.js +109 -0
  53. package/lib/utils/getTrace.js.map +1 -0
  54. package/lib/utils/intersectionObserverPolyfill.d.ts +1 -0
  55. package/lib/utils/intersectionObserverPolyfill.d.ts.map +1 -0
  56. package/lib/utils/intersectionObserverPolyfill.js +421 -0
  57. package/lib/utils/intersectionObserverPolyfill.js.map +1 -0
  58. package/lib/utils/scroll.d.ts +18 -0
  59. package/lib/utils/scroll.d.ts.map +1 -0
  60. package/lib/utils/scroll.js +75 -0
  61. package/lib/utils/scroll.js.map +1 -0
  62. package/lib/utils/yupValidator.d.ts +87 -0
  63. package/lib/utils/yupValidator.d.ts.map +1 -0
  64. package/lib/utils/yupValidator.js +189 -0
  65. package/lib/utils/yupValidator.js.map +1 -0
  66. package/lib/ytIframeTracking/index.d.ts +27 -0
  67. package/lib/ytIframeTracking/index.d.ts.map +1 -0
  68. package/lib/ytIframeTracking/index.js +165 -0
  69. package/lib/ytIframeTracking/index.js.map +1 -0
  70. package/package.json +75 -0
  71. package/src/FTTracking/index.ts +74 -0
  72. package/src/consentMonitor/index.ts +120 -0
  73. package/src/gaTracker/index.ts +136 -0
  74. package/src/index.ts +12 -0
  75. package/src/oTracker/index.ts +122 -0
  76. package/src/permutiveVideoUtils/index.ts +53 -0
  77. package/src/reactPlayerTracking/index.ts +105 -0
  78. package/src/types.d.ts +33 -0
  79. package/src/utils/attention.js +138 -0
  80. package/src/utils/cookies.js +9 -0
  81. package/src/utils/getTrace.js +122 -0
  82. package/src/utils/intersectionObserverPolyfill.js +470 -0
  83. package/src/utils/scroll.ts +94 -0
  84. package/src/utils/yupValidator.ts +205 -0
  85. package/src/ytIframeTracking/index.ts +210 -0
  86. package/test/index.test.tsx +63 -0
  87. package/tsconfig.json +26 -0
  88. package/tsconfig.test.json +6 -0
package/.babelrc ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "presets": [
3
+ "@babel/preset-env",
4
+ "@babel/preset-typescript"
5
+ ]
6
+ }
package/.eslintrc ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "env": {
3
+ "browser": true,
4
+ "node": true,
5
+ "es6": true,
6
+ "jest": true
7
+ },
8
+ "parser": "@typescript-eslint/parser",
9
+ "parserOptions": {
10
+ "jsx": true,
11
+ "useJSXTextNode": true
12
+ },
13
+ "settings": {
14
+ "react": {
15
+ "version": "detect"
16
+ }
17
+ },
18
+ "plugins": ["prettier", "eslint-plugin-import"],
19
+ "extends": [
20
+ "plugin:react/recommended",
21
+ "plugin:react-hooks/recommended",
22
+ "plugin:@typescript-eslint/recommended",
23
+ "plugin:prettier/recommended"
24
+ ],
25
+ "rules": {
26
+ "react-hooks/rules-of-hooks": "error",
27
+ "react-hooks/exhaustive-deps": "error",
28
+ "react/react-in-jsx-scope": "off",
29
+ "@typescript-eslint/explicit-function-return-type": "off",
30
+ "@typescript-eslint/explicit-module-boundary-types": "off",
31
+ "@typescript-eslint/ban-ts-comment": "off",
32
+ "@typescript-eslint/no-explicit-any": "off",
33
+ "react/prop-types": "off",
34
+ "import/order": [
35
+ "error",
36
+ {
37
+ "groups": ["builtin", "external", "internal"],
38
+ "pathGroups": [
39
+ {
40
+ "pattern": "react",
41
+ "group": "external",
42
+ "position": "before"
43
+ }
44
+ ],
45
+ "pathGroupsExcludedImportTypes": ["react"],
46
+ "newlines-between": "always",
47
+ "alphabetize": {
48
+ "order": "asc",
49
+ "caseInsensitive": true
50
+ }
51
+ }
52
+ ],
53
+ "prettier/prettier": "error"
54
+ },
55
+ "globals": {
56
+ "React": "writable"
57
+ }
58
+ }
@@ -0,0 +1 @@
1
+ * @digitaljohn
@@ -0,0 +1,31 @@
1
+ name: test
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - master
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+
12
+ strategy:
13
+ matrix:
14
+ node-version: [12.x, 14.x]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v1
18
+
19
+ - name: Use Node.js ${{ matrix.node-version }}
20
+ uses: actions/setup-node@v1
21
+ with:
22
+ node-version: ${{ matrix.node-version }}
23
+
24
+ - name: npm install, build, and test
25
+ run: |
26
+ npm ci
27
+ npm run build --if-present
28
+ npm run lint
29
+ npm test
30
+ env:
31
+ CI: true
@@ -0,0 +1,44 @@
1
+ name: release
2
+
3
+ on:
4
+ release:
5
+ types: [created]
6
+
7
+ jobs:
8
+ test:
9
+ runs-on: ubuntu-latest
10
+
11
+ strategy:
12
+ matrix:
13
+ node-version: [12.x, 14.x]
14
+
15
+ steps:
16
+ - uses: actions/checkout@v1
17
+
18
+ - name: Use Node.js ${{ matrix.node-version }}
19
+ uses: actions/setup-node@v1
20
+ with:
21
+ node-version: ${{ matrix.node-version }}
22
+
23
+ - name: npm install, build, and test
24
+ run: |
25
+ npm ci
26
+ npm run build --if-present
27
+ npm run lint
28
+ npm test
29
+ env:
30
+ CI: true
31
+
32
+ publish-npm:
33
+ needs: test
34
+ runs-on: ubuntu-latest
35
+ steps:
36
+ - uses: actions/checkout@v2
37
+ - uses: actions/setup-node@v1
38
+ with:
39
+ node-version: 14
40
+ registry-url: https://registry.npmjs.org/
41
+ - run: npm ci
42
+ - run: npm publish --access=public
43
+ env:
44
+ NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ v16.13.2
@@ -0,0 +1,5 @@
1
+ node_modules
2
+ coverage
3
+ dist
4
+ public
5
+ tmp
@@ -0,0 +1,76 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, sex characteristics, gender identity and expression,
9
+ level of experience, education, socio-economic status, nationality, personal
10
+ appearance, race, religion, or sexual identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ - Using welcoming and inclusive language
18
+ - Being respectful of differing viewpoints and experiences
19
+ - Gracefully accepting constructive criticism
20
+ - Focusing on what is best for the community
21
+ - Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ - The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ - Trolling, insulting/derogatory comments, and personal or political attacks
28
+ - Public or private harassment
29
+ - Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ - Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at developers@phntms.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72
+
73
+ [homepage]: https://www.contributor-covenant.org
74
+
75
+ For answers to common questions about this code of conduct, see
76
+ https://www.contributor-covenant.org/faq
@@ -0,0 +1,48 @@
1
+ # How to contribute
2
+
3
+ I'm really happy that you're interested in helping out with this little project.
4
+
5
+ As this is very early days for the project there's not a lot in the way of
6
+ resources, but please check out the [documentation](./README.md), and also the
7
+ [list of issues](https://github.com/phantomstudios/@phntms/ft-lib/issues).
8
+
9
+ Please submit an issue if you need help with anything.
10
+
11
+ We have a [code of conduct](./CODE_OF_CONDUCT.md) so please make sure you follow
12
+ it.
13
+
14
+ ## Testing
15
+
16
+ Testing is performed using `jest` and is tested on Windows, Linux and MacOS with
17
+ Node 10 and 12 runtimes. For a PR to be considered all these environments need to
18
+ pass. Testing is automated using GitHub Actions CI.
19
+
20
+ ## Submitting changes
21
+
22
+ Please send a
23
+ [GitHub Pull Request to @phntms/ft-lib](https://github.com/phantomstudios/@phntms/ft-lib/pull/new/master)
24
+ with a clear list of what you've done (read more about
25
+ [pull requests](https://help.github.com/en/articles/about-pull-requests)). When you send a pull
26
+ request, please make sure you've covered off all the points in the template.
27
+
28
+ Make sure you've read about our workflow (below); in essence make sure each Pull
29
+ Request is atomic but don't worry too much about the commits themselves as we use
30
+ squash-and-merge.
31
+
32
+ ## Our workflow
33
+
34
+ We use [GitHub flow](https://guides.github.com/introduction/flow/); it's a lot
35
+ like git-flow but simpler and more forgiving. We use the `squash and merge`
36
+ strategy to merge Pull Requests.
37
+
38
+ In effect this means:
39
+
40
+ - Don't worry about individual commits. They will be preserved, but not on the
41
+ main `master` branch history, so feel free to commit early and often, using
42
+ git as a save mechanism.
43
+ - Your Pull Request title and description become very important; they are the
44
+ history of the master branch and explain all the changes.
45
+ - You ought to be able to find any previous version easily using GitHub tabs, or
46
+ [Releases](https://github.com/phantomstudios/@phntms/ft-lib/releases)
47
+
48
+ Thanks, John Chipps-Harding
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Phantom Studios Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,158 @@
1
+ # ft-lib
2
+
3
+ [![NPM version][npm-image]][npm-url]
4
+ [![Actions Status][ci-image]][ci-url]
5
+ [![PR Welcome][npm-downloads-image]][npm-downloads-url]
6
+
7
+ A collection of Javascript utils for shareable UI and tracking functionality across Phantom FT sites
8
+
9
+ ## Introduction
10
+
11
+ currently implemented:
12
+
13
+ - FTTracking - Consolidated Origami and GA/GTM event tracking for page and interaction events.
14
+ - consentMonitor - polls the FT consent cookies set by the approved FT Origami cookie banner to enable/disable the FT Permutive ad tracking
15
+ - permutiveVideoUtils - formatted permutive video progress events
16
+ - reactPlayerTracking - Video tracking for FT sites implementing videos with [react-player](https://github.com/cookpete/react-player)
17
+ - ytIframeEventHandler - Video tracking handler for FT sites with embedded Youtube Iframe API videos.
18
+
19
+ ## Installation
20
+
21
+ Install this package with `npm`.
22
+
23
+ ```bash
24
+ npm i @phntms/ft-lib
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ### FTTracking
30
+
31
+ Shared Origami and GA/GTM tracking implementation that can be used across all Phantom FT sites. Tracking meta data is provided by a config object when first initiated and on subsequent route changes (only required for SPA/NextJS sites).
32
+ By default, the implementation will automatically handle FT tracking via `data-gadl` and `data-o-event` HTML attributes. The tracker instance should be added to the global window namespace if custom events are required.
33
+ Note: By default the FTTracker instance will load the `consentMonitor` poller, so sites do not need to implement this separately.
34
+
35
+ The constructor requires the config JSON object (TODO - schema) and optionally accepts an options object:
36
+
37
+ #### Default options
38
+
39
+ ```
40
+ scrollTrackerSelector: "#o_tracker_scroll", //top level DOM element selector for scroll tracking
41
+ isCustomGTMEvent: true, //selects between GTM and UA(GTAG) event formats - TODO - handle automatically by detecting loaded GTM/UA?
42
+
43
+ ```
44
+
45
+ #### Config/Event format validator
46
+
47
+ The site config JSON object passed in the constructor and all events handled by FTTracker are validated with Yup for a basic format check. This includes both the automatic `data-o-event`, `data-gadl` generated events and manually fired events with `FTTracker.oEvent` and `FTTracker.gaEvent`. A console error is thrown if validation fails. The validation rules can be found in `/src/utils/yupValidator.ts`
48
+
49
+ Typical usage:
50
+
51
+ ```Javascript
52
+ import { FTTracking } from '@phntms/ft-lib'
53
+
54
+ //For Wagtail sites, get server-rendered o-tracking-data
55
+ const config = JSON.parse(document.getElementById('o-tracking-data').textContent)
56
+ window.FTTracker = new FTTracking(config, { scrollTrackerSelector: '#content' })
57
+ .
58
+ .
59
+ //if an event needs to be fired that can't be added using the preferred data-gadl and data-o-event attributes (i.e. custom players or form submits):
60
+ window.FTTracker.oEvent({category: "audio", action: "progress", duration: duration, progress: {`${progress}%`}})
61
+ window.FTTracker.gaEvent(`Audio`, {`${progress}% progress`}, <AUDIO or PAGE TITLE>)
62
+ ```
63
+
64
+ ### consentMonitor
65
+
66
+ Adds an FT consent cookie poller to enable/disable Permutive consent (only useful if 'consentRequired' is set as an option in the site's Permutive script - see [here](https://support.permutive.com/hc/en-us/articles/360010845519-Seeking-User-Consent#h_00327830-509b-422a-952b-1906264031f1)
67
+ There are optional constructor args for the hostname (defaults to window.location.hostname) and the dev environment host matches (defaults to ["localhost", "phq", "vercel.app"]) which are used to determine development environments in order to generate an FT banner event listener ((see [here](https://registry.origami.ft.com/components/o-cookie-message@6.0.1/readme?brand=master) for a list of banner DOM events) to set session-level cookies for development environments
68
+
69
+ ```Javascript
70
+ import { consentMonitor } from "@phntms/ft-lib";
71
+
72
+ new consentMonitor("FT.staging.testsite.com". ["localhost", "phq", "staging"]);
73
+ ```
74
+
75
+ ### permutiveVideoUtils
76
+
77
+ emitPermutiveProgressEvents - used within a video player's progress event handler to fire Permutive video progress events at [0, 25, 50, 75, 100] percent progress.
78
+ Optional 3rd arg to pass a window.interval instance to be cleared once progress is complete.
79
+
80
+ ```Javascript
81
+ import { permutiveVideoUtils } from "@phntms/ft-lib";
82
+
83
+ const permutivevideoTracker = new permutiveVideoUtils("<FT-CAMPAIGN>","<VIDEO-TITLE>","<VIDEO-ID/URL>") //Data will be site implementation specific
84
+
85
+ player.on("progress", () => { //event will be video player site implementation specific
86
+ permutivevideoTracker.emitPermutiveProgressEvent(<DURATION>, <CURRENTTIME>, <OPTIONAL-WINDOW-INTERVAL>)
87
+ });
88
+ ```
89
+
90
+ ### reactPlayerTracking
91
+
92
+ Exports video event handlers that broadcast the required GA, oTracking and Permutive events.
93
+
94
+ The constructor takes the parent site's FTTracking instance (typically set up as window.FTTracker) and video and site meta data (as required for the tracking data).
95
+
96
+ Typical implementation:
97
+
98
+ ```Javascript
99
+ import { reactPlayerTracking } from "@phntms/ft-lib";
100
+
101
+ const [videoTracker] = useState(
102
+ new reactPlayerTracking(window.FTTracker, <VIDEO-TITLE>, <VIDEO-URL>),
103
+ )
104
+
105
+ <ReactPlayer
106
+ onDuration={videoTracker.setDuration}
107
+ onEnded={videoTracker.trackEnded}
108
+ onPause={videoTracker.trackPause}
109
+ onPlay={videoTracker.trackPlay}
110
+ onProgress={videoTracker.trackProgress}
111
+ >
112
+ ```
113
+
114
+ ### ytIframeTracking
115
+
116
+ Exports a Youtube iframe event handler for sites using the Youtube Iframe API that broadcasts the required GA, oTracking and Permutive events.
117
+ The Youtube iFrame can be either generated in the site's JS or template rendered.
118
+
119
+ The constructor takes the parent site's FTTracking instance (typically set up as window.FTTracker).
120
+
121
+ NOTE: For Typescript usage as below, the @types/youtube NPM package should be added to the parent project and the YT namespace added to tsconfig.json with the `"types": ["youtube"]` compiler option.
122
+
123
+ Typical implementation:
124
+
125
+ ```Javascript
126
+ import { ytIframeTracking } from '@phntms/ft-lib';
127
+
128
+ const VIDEO_IFRAME_ID = 'video-iframe';
129
+
130
+ export class YoutubeIframeLoader {
131
+ videoTracker: ytIframeTracking;
132
+ player?: YT.Player;
133
+
134
+ constructor() {
135
+ this.videoTracker = new ytIframeTracking(window.FTTracker);
136
+
137
+ window.onYouTubeIframeAPIReady =
138
+ (event: YT.PlayerEvent) => {
139
+ this.player = new YT.Player(VIDEO_IFRAME_ID, {
140
+ events: {
141
+ 'onStateChange': (event) => this.onPlayerStateChange(event)
142
+ }
143
+ });
144
+ };
145
+
146
+ onPlayerStateChange(event: YT.PlayerEvent) {
147
+ this.videoTracker.ytIframeEventHandler(event);
148
+ }
149
+ }
150
+ }
151
+ ```
152
+
153
+ [npm-image]: https://img.shields.io/npm/v/@phntms/ft-lib.svg?style=flat-square&logo=react
154
+ [npm-url]: https://npmjs.org/package/@phntms/ft-lib
155
+ [npm-downloads-image]: https://img.shields.io/npm/dm/@phntms/ft-lib.svg
156
+ [npm-downloads-url]: https://npmcharts.com/compare/@phntms/ft-lib?minimal=true
157
+ [ci-image]: https://github.com/phantomstudios/ft-lib/workflows/test/badge.svg
158
+ [ci-url]: https://github.com/phantomstudios/ft-lib/actions
package/SUPPORT.md ADDED
@@ -0,0 +1,4 @@
1
+ # @phntms/ft-lib Support
2
+
3
+ For _questions_ on how to use `@phntms/ft-lib` or what went wrong when you tried something, our primary resource is by opening a
4
+ [GitHub Issue](https://github.com/phantomstudios/@phntms/ft-lib/issues), where you can get help from developers.
package/jest.config.js ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @type {jest.ProjectConfig}
3
+ */
4
+ module.exports = {
5
+ roots: [
6
+ '<rootDir>/test'
7
+ ],
8
+ transform: {
9
+ '^.+\\.tsx?$': 'ts-jest'
10
+ },
11
+ moduleFileExtensions: [
12
+ 'ts',
13
+ 'tsx',
14
+ 'js',
15
+ 'jsx',
16
+ 'json',
17
+ 'node'
18
+ ],
19
+ globals: {
20
+ 'ts-jest': {
21
+ tsConfig: 'tsconfig.test.json'
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,24 @@
1
+ import { gaTracker } from "../gaTracker";
2
+ import { oTracker } from "../oTracker";
3
+ import { ScrollTracker } from "../utils/scroll";
4
+ import { ConfigType, OrigamiEventType } from "../utils/yupValidator";
5
+ export interface TrackingOptions {
6
+ scrollTrackerSelector?: string;
7
+ isCustomGTMEvent?: boolean;
8
+ sendGTMPageViewYN?: boolean;
9
+ }
10
+ export declare class FTTracking {
11
+ private _config;
12
+ options: TrackingOptions;
13
+ oTracker: oTracker;
14
+ gaTracker: gaTracker;
15
+ scrollTracker: ScrollTracker;
16
+ oEvent: (detail: OrigamiEventType) => void;
17
+ gaEvent: (category: string, action: string, label: string) => void;
18
+ gtmEvent: (category: string, action: string, label: string) => void;
19
+ constructor(config: ConfigType, options?: TrackingOptions);
20
+ set config(c: ConfigType);
21
+ get config(): ConfigType;
22
+ newPageView(config: ConfigType): void;
23
+ }
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/FTTracking/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAEL,UAAU,EACV,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,WAAW,eAAe;IAC9B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAQD,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,EAAE,eAAe,CAAC;IACzB,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,aAAa,EAAE,aAAa,CAAC;IAC7B,MAAM,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAC3C,OAAO,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnE,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;gBAExD,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,eAAe;IAqBzD,IAAI,MAAM,CAAC,CAAC,EAAE,UAAU,EAGvB;IACD,IAAI,MAAM,IAJI,UAAU,CAMvB;IAEM,WAAW,CAAC,MAAM,EAAE,UAAU;CAYtC"}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.FTTracking = void 0;
15
+ var consentMonitor_1 = require("../consentMonitor");
16
+ var gaTracker_1 = require("../gaTracker");
17
+ var oTracker_1 = require("../oTracker");
18
+ var scroll_1 = require("../utils/scroll");
19
+ var yupValidator_1 = require("../utils/yupValidator");
20
+ var DEFAULT_OPTIONS = {
21
+ scrollTrackerSelector: "#o_tracker_scroll",
22
+ isCustomGTMEvent: true,
23
+ sendGTMPageViewYN: true,
24
+ };
25
+ var FTTracking = /** @class */ (function () {
26
+ function FTTracking(config, options) {
27
+ this.options = __assign(__assign({}, DEFAULT_OPTIONS), options);
28
+ this.oTracker = new oTracker_1.oTracker(config, this.options);
29
+ this.gaTracker = new gaTracker_1.gaTracker(this.options);
30
+ this.oEvent = this.oTracker.eventDispatcher;
31
+ this.gaEvent = this.options.isCustomGTMEvent
32
+ ? this.gaTracker.GTMEventDispatcher
33
+ : this.gaTracker.GtagEventDispatcher;
34
+ this._config = config;
35
+ //backwards compatibility
36
+ this.gtmEvent = this.gaEvent;
37
+ this.scrollTracker = new scroll_1.ScrollTracker(this);
38
+ //cookie consent monitor for permutive tracking
39
+ window.addEventListener("load", function () {
40
+ new consentMonitor_1.consentMonitor(window.location.hostname, [".app", "preview"]);
41
+ });
42
+ }
43
+ Object.defineProperty(FTTracking.prototype, "config", {
44
+ get: function () {
45
+ return this._config;
46
+ },
47
+ set: function (c) {
48
+ this._config = c;
49
+ this.oTracker.config = c;
50
+ },
51
+ enumerable: false,
52
+ configurable: true
53
+ });
54
+ FTTracking.prototype.newPageView = function (config) {
55
+ //Update passed config to otracker,send pageview events and reset scrollTracker
56
+ (0, yupValidator_1.validateConfig)(config);
57
+ this.oTracker.config = config;
58
+ this.oTracker.broadcastPageView();
59
+ this.oTracker.broadcastBrandedContent();
60
+ this.scrollTracker.reset();
61
+ if (this.options.sendGTMPageViewYN) {
62
+ this.gaTracker.GTMVirtualPageView(this.config.url, this.config.title);
63
+ }
64
+ //ga pageview event required for sites without GTM?
65
+ };
66
+ return FTTracking;
67
+ }());
68
+ exports.FTTracking = FTTracking;
69
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/FTTracking/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,oDAAmD;AACnD,0CAAyC;AACzC,wCAAuC;AACvC,0CAAgD;AAChD,sDAI+B;AAQ/B,IAAM,eAAe,GAAG;IACtB,qBAAqB,EAAE,mBAAmB;IAC1C,gBAAgB,EAAE,IAAI;IACtB,iBAAiB,EAAE,IAAI;CACxB,CAAC;AAEF;IAUE,oBAAY,MAAkB,EAAE,OAAyB;QACvD,IAAI,CAAC,OAAO,yBAAQ,eAAe,GAAK,OAAO,CAAE,CAAC;QAClD,IAAI,CAAC,QAAQ,GAAG,IAAI,mBAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACnD,IAAI,CAAC,SAAS,GAAG,IAAI,qBAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAE7C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC;QAC5C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB;YAC1C,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,kBAAkB;YACnC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC;QACvC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QAEtB,yBAAyB;QACzB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC;QAE7B,IAAI,CAAC,aAAa,GAAG,IAAI,sBAAa,CAAC,IAAI,CAAC,CAAC;QAE7C,+CAA+C;QAC/C,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE;YAC9B,IAAI,+BAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;QACpE,CAAC,CAAC,CAAC;IACL,CAAC;IACD,sBAAI,8BAAM;aAIV;YACE,OAAO,IAAI,CAAC,OAAO,CAAC;QACtB,CAAC;aAND,UAAW,CAAa;YACtB,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;YACjB,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;QAC3B,CAAC;;;OAAA;IAKM,gCAAW,GAAlB,UAAmB,MAAkB;QACnC,+EAA+E;QAC/E,IAAA,6BAAc,EAAC,MAAM,CAAC,CAAC;QACvB,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;QAC9B,IAAI,CAAC,QAAQ,CAAC,iBAAiB,EAAE,CAAC;QAClC,IAAI,CAAC,QAAQ,CAAC,uBAAuB,EAAE,CAAC;QACxC,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE;YAClC,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SACvE;QACD,mDAAmD;IACrD,CAAC;IACH,iBAAC;AAAD,CAAC,AAnDD,IAmDC;AAnDY,gCAAU"}
@@ -0,0 +1,19 @@
1
+ export declare class consentMonitor {
2
+ protected _consent: boolean;
3
+ protected _devHosts: string[];
4
+ protected _isDevEnvironment: boolean;
5
+ protected _hostname: string;
6
+ protected _isInitialized: boolean;
7
+ constructor(hostname?: string, devHosts?: string[] | string);
8
+ get consent(): boolean;
9
+ get devHosts(): string[] | string;
10
+ get isDevEnvironment(): boolean;
11
+ get isInitialized(): boolean;
12
+ getCookieValue: (name: string) => string;
13
+ init: () => void;
14
+ cookieConsentTest: () => void;
15
+ setDevCookieHandler: () => void;
16
+ permutiveConsentOn: () => void;
17
+ permutiveConsentOff: () => void;
18
+ }
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/consentMonitor/index.ts"],"names":[],"mappings":"AAKA,qBAAa,cAAc;IACzB,SAAS,CAAC,QAAQ,UAAS;IAC3B,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;IAC9B,SAAS,CAAC,iBAAiB,UAAS;IACpC,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,cAAc,UAAS;gBAErB,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM;IAc3D,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,QAAQ,IAAI,MAAM,EAAE,GAAG,MAAM,CAEhC;IAED,IAAI,gBAAgB,IAAI,OAAO,CAE9B;IAED,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED,cAAc,SAAU,MAAM,YACgD;IAE9E,IAAI,aASF;IAEF,iBAAiB,aA6Bf;IAEF,mBAAmB,aAkBjB;IAEF,kBAAkB,aAMhB;IAEF,mBAAmB,aAGjB;CACH"}