Skip to content

Commit d37001f

Browse files
committed
refactor(major): Upgrade to Vite, add demo, remove optional libs
- Migrate from Create-React-App to Vite - Add demo playground with examples - Add prettier for code formatting - Remove dev-dependencies: styled-components and AntD
1 parent 12c182c commit d37001f

File tree

205 files changed

+7323
-73201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

205 files changed

+7323
-73201
lines changed

.github/workflows/docs.yml

+41-38
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,46 @@
11
name: Generate Documentation
22

33
on:
4-
push:
5-
branches:
6-
- main # Run on pushes to the main branch
7-
pull_request:
8-
branches:
9-
- main
4+
push:
5+
branches:
6+
- main # Run on pushes to the main branch
7+
pull_request:
8+
branches:
9+
- main
1010

1111
jobs:
12-
generate-docs:
13-
runs-on: ubuntu-latest
14-
steps:
15-
- name: Checkout code
16-
uses: actions/checkout@v3
17-
18-
- name: Set up Node.js
19-
uses: actions/setup-node@v3
20-
with:
21-
node-version: 'latest'
22-
cache: 'npm'
23-
24-
- name: Install dependencies
25-
run: npm install @microsoft/tsdoc typedoc
26-
27-
- name: Generate documentation
28-
run: npm run docs
29-
30-
- name: Upload documentation to GitHub Pages
31-
uses: actions/upload-pages-artifact@v1
32-
with:
33-
path: ./public/docs # Path where docs are generated
34-
35-
deploy:
36-
needs: generate-docs
37-
runs-on: ubuntu-latest
38-
permissions:
39-
pages: write
40-
id-token: write
41-
steps:
42-
- name: Deploy to GitHub Pages
43-
uses: actions/deploy-pages@v1
12+
deploy-website:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: 'latest'
22+
cache: 'npm'
23+
24+
- name: Install dependencies
25+
run: npm install
26+
27+
- name: Generate documentation
28+
run: npm run build-demo && npm run docs
29+
30+
- name: Setup Pages
31+
uses: actions/configure-pages@v4
32+
33+
- name: Upload documentation to GitHub Pages
34+
uses: actions/upload-pages-artifact@v3
35+
with:
36+
path: './dist' # Path where docs are generated
37+
38+
deploy:
39+
needs: deploy-website
40+
runs-on: ubuntu-latest
41+
permissions:
42+
pages: write
43+
id-token: write
44+
steps:
45+
- name: Deploy to GitHub Pages
46+
uses: actions/deploy-pages@v4

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@
2121
npm-debug.log*
2222
yarn-debug.log*
2323
yarn-error.log*
24+
25+
*storybook.log

.gitlab-ci.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ image: node:latest
55
# This folder is cached between builds
66
# http://docs.gitlab.com/ee/ci/yaml/README.html#cache
77
cache:
8-
paths:
9-
- node_modules/
8+
paths:
9+
- node_modules/
1010

1111
# Instructions to GitLab Runner for generating API documentation on Gitlab Pages
1212
pages:
13-
script:
14-
- npm install @microsoft/tsdoc typedoc
15-
- npm run docs
16-
artifacts:
17-
paths:
18-
- public/docs
13+
script:
14+
- npm install @microsoft/tsdoc typedoc
15+
- npm run docs
16+
artifacts:
17+
paths:
18+
- public/docs

.prettierrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"trailingComma": "all",
3+
"tabWidth": 4,
4+
"semi": true,
5+
"singleQuote": true
6+
}

.storybook/main.js

-12
This file was deleted.

.storybook/preview.js

-4
This file was deleted.

.vscode/settings.json

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
11
{
2-
}
2+
"workbench.colorCustomizations": {
3+
"activityBar.activeBackground": "#fa1b49",
4+
"activityBar.background": "#fa1b49",
5+
"activityBar.foreground": "#e7e7e7",
6+
"activityBar.inactiveForeground": "#e7e7e799",
7+
"activityBarBadge.background": "#155e02",
8+
"activityBarBadge.foreground": "#e7e7e7",
9+
"commandCenter.border": "#e7e7e799",
10+
"sash.hoverBorder": "#fa1b49",
11+
"statusBar.background": "#dd0531",
12+
"statusBar.foreground": "#e7e7e7",
13+
"statusBarItem.hoverBackground": "#fa1b49",
14+
"statusBarItem.remoteBackground": "#dd0531",
15+
"statusBarItem.remoteForeground": "#e7e7e7",
16+
"titleBar.activeBackground": "#dd0531",
17+
"titleBar.activeForeground": "#e7e7e7",
18+
"titleBar.inactiveBackground": "#dd053199",
19+
"titleBar.inactiveForeground": "#e7e7e799"
20+
},
21+
"peacock.color": "#dd0531"
22+
}

README.md

+42-44
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
1-
# User Analytics
1+
# React User Analytics
22

33
This library enables tracking of UI events when a user interacts with a React or React Native application.
44

55
## Features
6+
67
- **Progressive** - Uses latest JavaScript features and design patterns for a React codebase.
78
- **Extensible** - A modular architecture and usage of Dependency.Inversion patterns gives you flexibility and allows you to easily extend features.
89
- **TypeScript support**.
910

1011
## Supported events
12+
1113
- Form Events
12-
- `onChange`
14+
- `onChange`
1315
- Mouse Events
14-
- `onClick`
15-
- `onHover`
16-
16+
- `onClick`
17+
- `onHover`
1718

1819
## Work in Progress
20+
1921
- Eventually, the library will have exhaustive coverage and support for many more events, such as:
20-
- Wheel Events
21-
- Touch Events
22-
- Keyboard Events
23-
- Mouse Events
24-
- and more.
22+
23+
- Wheel Events
24+
- Touch Events
25+
- Keyboard Events
26+
- Mouse Events
27+
- and more.
2528

2629
- User Interaction journey mapping
2730
- Session Recording
2831

29-
3032
## Instructions of Usage
33+
3134
1. First, import the library in your project.
3235

3336
2. In-order to add user-tracking ability to your component or element, import the `withTracking` function (Higher-order component) and wrap the component. Here's an example using a simple `Button` component:
@@ -38,7 +41,7 @@ This library enables tracking of UI events when a user interacts with a React or
3841

3942
3. Finally, use `ButtonWithTracking` inside your app anywhere where you'd like to track user-events occurring on this component, such as `onClick` or `onHover`.
4043

41-
```
44+
```react
4245
import Button, { ButtonWithTracking } from '../../elements/Button';
4346
4447
function Home() {
@@ -70,7 +73,7 @@ function Home() {
7073
track: logEvent, // callback function that runs whenever the event occurs
7174
}
7275
]}
73-
>
76+
>
7477
)
7578
}
7679
@@ -79,7 +82,6 @@ export default Home;
7982

8083
You can add multiple tracker objects within the `trackers` array if you need to track more than one event occurring within the component.
8184

82-
8385
## Advanced Usage
8486

8587
### Mapping a user's journey
@@ -90,9 +92,11 @@ Say you have 2 react components - a `ButtonWithTracking` configured to track `on
9092
In this scenario, it is useful to capture a global 'context' within which the events occur - such as the page or the container component details, and the app version. This information is useful to plot out the user's journey, which will give you a more contextual understanding of how the user navigates through your app.
9193

9294
- #### Provide and capture contextual data using React Context Provider `<DataContext.Provider>`
93-
Using the `<DataContext.Provider>`, you can provide the global 'context' to your tracking components without having to pass them explicitly via props. Here's how:
9495

95-
- Create a `DataContext` object.
96+
Using the `<DataContext.Provider>`, you can provide the global 'context' to your tracking components without having to pass them explicitly via props. Here's how:
97+
98+
- Create a `DataContext` object.
99+
96100
```
97101
const dataContext = {
98102
context: "Login Form",
@@ -102,9 +106,9 @@ const dataContext = {
102106
} as UserInteraction.DataContext;
103107
```
104108

105-
- Next, wrap your template or container component within `DataContext.Provider` and provide it the `dataContext` value:
109+
- Next, wrap your template or container component within `DataContext.Provider` and provide it the `dataContext` value:
106110

107-
```
111+
```react
108112
import { DataContext } from '../../../library/user-analytics/react/contexts/dataContext';
109113
import Button, { ButtonWithTracking } from '../../elements/Button';
110114
@@ -130,14 +134,14 @@ function LoginForm() {
130134
{
131135
action: "onClick",
132136
track: logEvent,
133-
137+
134138
data: { // pass optional custom data
135139
color: "blue",
136140
}
137141
}
138142
]}
139-
>
140-
</DataContext.Provider>
143+
>
144+
</DataContext.Provider>
141145
)
142146
}
143147
@@ -147,12 +151,11 @@ export default LoginForm;
147151

148152
This way, your tracking components nested anywhere within the provider will receive the `dataContext` object and will return it as part of the `UserInteractionResource` object.
149153

150-
151154
- #### Providing Data Context as regular props
152155

153156
If you don't want to provide data using `DataContext.Provider` or want to override it with a different value, you can pass them explicitly via props:
154157

155-
```
158+
```react
156159
function LoginForm() {
157160
158161
function logEvent(
@@ -174,20 +177,20 @@ function LoginForm() {
174177
{
175178
action: "onClick",
176179
track: logEvent,
177-
180+
178181
data: { // pass optional custom data
179182
color: "blue",
180183
}
181184
}
182185
]}
183-
186+
184187
dataContext={{ // Pass dataContext explicitly
185188
app: {
186189
version: "0",
187190
},
188191
context: "Login Form"
189192
}}
190-
>
193+
>
191194
)
192195
}
193196
@@ -197,7 +200,6 @@ export default LoginForm;
197200

198201
In-case you have both in your application, the data context passed via props will override the values from ` <DataContext.Provider>`
199202

200-
201203
## API
202204

203205
### React
@@ -206,29 +208,26 @@ In-case you have both in your application, the data context passed via props wil
206208

207209
The tracking-enabled component will accept all props required for the original component, along with the following:
208210

209-
| Props | Required | Description | Type |
210-
| :--- | :----: | :----: | ---: |
211-
| `trackers` |Yes |Each tracker object expects an `action` and `track` properties. Check the section below for the complete list of properties | `UserInteraction.Tracker[]` |
212-
| `origin` |Optional | To provide some contextual information for the event origin | `string` |
213-
| `dataContext` |Optional |an object property to provide context of the taken event | `UserInteraction.DataContext`|
214-
211+
| Props | Required | Description | Type |
212+
| :------------ | :------: | :-------------------------------------------------------------------------------------------------------------------------: | ----------------------------: |
213+
| `trackers` | Yes | Each tracker object expects an `action` and `track` properties. Check the section below for the complete list of properties | `UserInteraction.Tracker[]` |
214+
| `origin` | Optional | To provide some contextual information for the event origin | `string` |
215+
| `dataContext` | Optional | an object property to provide context of the taken event | `UserInteraction.DataContext` |
215216

216217
- #### `UserInteraction.Tracker` object properties
217218

218-
| Property | Required | Description | Type |
219-
| :--- | :----: | :----: | ---: |
220-
| `action` | Yes | Type of event that needs to be tracked (React Synthetic events). Can take values such as `onClick`, `onChange` | `string` |
221-
| `track` | Yes| Callback that runs when above event occurs | `(e, interactionResource: UserInteractionResource) => void` |
222-
| `data` | Optional | Can be used to provide some custom data. Accessible within `UserInteractionResource.data` | `Object<any>` |
223-
224-
219+
| Property | Required | Description | Type |
220+
| :------- | :------: | :------------------------------------------------------------------------------------------------------------: | ----------------------------------------------------------: |
221+
| `action` | Yes | Type of event that needs to be tracked (React Synthetic events). Can take values such as `onClick`, `onChange` | `string` |
222+
| `track` | Yes | Callback that runs when above event occurs | `(e, interactionResource: UserInteractionResource) => void` |
223+
| `data` | Optional | Can be used to provide some custom data. Accessible within `UserInteractionResource.data` | `Object<any>` |
225224

226225
### Interfaces
227226

228227
- #### `UserInteractionResource`
229-
The `UserInteractionResource` object contains all properties from `BaseResource`, along with the following:
228+
The `UserInteractionResource` object contains all properties from `BaseResource`, along with the following:
230229

231-
```
230+
```typescript
232231
type: typeof UserInteraction.TYPE; // "UserInteraction"
233232
action: UserInteraction.Action; // Type of the event, such as "onClick", "onChange"
234233
source: {
@@ -248,7 +247,7 @@ data?: Object<any>; // Additional custom data that needs to be captured
248247

249248
- #### `BaseResource`
250249

251-
```
250+
```typescript
252251
app: {
253252
version: string,
254253
};
@@ -272,4 +271,3 @@ os: {
272271

273272
## Check out the [docs](./docs) folder for a complete list of API reference.
274273

275-
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

0 commit comments

Comments
 (0)