Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions .github/dependabot.yml

This file was deleted.

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

- The SDK api has changed to match changes introduced in V4 version of the agent.
- Response field names follow the JavaScript Agent v4 API. For example, `visitorId` is now `visitor_id`, `requestId` is now `event_id`, and other response fields use snake_case.
- The default caching strategy has changed from `sessionStorage` caching to **no caching by default**, aligned with the underlying [JavaScript agent v4 default](https://docs.fingerprint.com/reference/js-agent-v4-start-function#cache).
- The default caching strategy has changed from `sessionStorage` caching to **no caching by default**, aligned with the underlying [JavaScript agent v4 default](https://docs.fingerprint.com/reference/js-agent-start-function#cache).

### Features

Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<a href="https://fingerprintjs.github.io/react/coverage/"><img src="https://fingerprintjs.github.io/react/coverage/badges.svg" alt="coverage"></a>
<a href="https://www.npmjs.com/package/@fingerprint/react"><img src="https://img.shields.io/npm/v/@fingerprint/react.svg" alt="Current NPM version"></a>
<a href="https://www.npmjs.com/package/@fingerprint/react"><img src="https://img.shields.io/npm/dm/@fingerprint/react.svg" alt="Monthly downloads from NPM"></a>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/:license-mit-blue.svg" alt="MIT license"></a>
<a href="https://discord.gg/39EpE2neBg"><img src="https://img.shields.io/discord/852099967190433792?style=logo&label=Discord&logo=Discord&logoColor=white" alt="Discord server"></a>
<a href="https://opensource.org/license/MIT"><img src="https://img.shields.io/:license-mit-blue.svg" alt="MIT license"></a>
<a href="https://discord.com/invite/39EpE2neBg"><img src="https://img.shields.io/discord/852099967190433792?style=logo&label=Discord&logo=Discord&logoColor=white" alt="Discord server"></a>
<a href="https://fingerprintjs.github.io/react/"><img src="https://img.shields.io/badge/-Documentation-green" alt="Documentation"></a>
</p>

Expand Down Expand Up @@ -69,16 +69,16 @@ pnpm add @fingerprint/react

## Getting started

In order to identify visitors, you'll need a Fingerprint account (you can [sign up for free](https://dashboard.fingerprint.com/signup/)).
In order to identify visitors, you'll need a Fingerprint account (you can [sign up for free](https://dashboard.fingerprint.com/signup)).
To get your API key and get started, see the [Fingerprint Quick Start Guide](https://docs.fingerprint.com/docs/quick-start-guide).

### 1. Wrap your application (or component) in `<FingerprintProvider>`.

- Set `apiKey` to your Fingerprint [Public API Key](https://dashboard.fingerprint.com/api-keys).
- Set `region` if you have chosen a non-global [region](https://docs.fingerprint.com/docs/regions) during registration.
- Set `endpoints` if you are using [one of our proxy integrations to increase accuracy](https://docs.fingerprint.com/docs/protecting-the-javascript-agent-from-adblockers) and effectiveness of visitor identification.
- You can use all the [start options](https://docs.fingerprint.com/reference/js-agent-v4-start-function#start-options) available in the JavaScript agent `start()` function.
- Caching is disabled by default. To enable caching, pass the JavaScript agent [`cache` start option](https://docs.fingerprint.com/reference/js-agent-v4-start-function#cache).
- You can use all the [start options](https://docs.fingerprint.com/reference/js-agent-start-function#start-options) available in the JavaScript agent `start()` function.
- Caching is disabled by default. To enable caching, pass the JavaScript agent [`cache` start option](https://docs.fingerprint.com/reference/js-agent-start-function#cache).

```jsx
// src/index.js
Expand All @@ -87,12 +87,12 @@ import ReactDOM from 'react-dom/client'
import { FingerprintProvider } from '@fingerprint/react'
import App from './App'

const root = ReactDOM.createRoot(document.getElementById('app'))
const root = ReactDOM.createRoot(document.getElementById('root'))

// <FingerprintProvider /> supports the same options as `start()` function.
root.render(
<FingerprintProvider
apiKey='your-public-api-key'
apiKey='PUBLIC_API_KEY'
cache={{ storage: 'sessionStorage', duration: 3600 }}
>
<App />
Expand Down Expand Up @@ -131,7 +131,7 @@ The `useVisitorData` hook also returns a `getData` method you can use to make an

- You can pass `{ immediate: false }` to `useVisitorData` to disable automatic visitor identification on render.

Both `useVisitorData` and `getData` accept all the [get options](https://docs.fingerprint.com/reference/get-function#get-options) available in the JavaScript agent `get` function.
Both `useVisitorData` and `getData` accept all the [get options](https://docs.fingerprint.com/reference/js-agent-get-function#get-options) available in the JavaScript agent `get` function.

The returned v4 visitor data uses raw response field names in snake_case, for example `visitor_id` and `event_id`.

Expand Down Expand Up @@ -209,7 +209,7 @@ function App() {

## Error handling

The `getData` function throws errors directly from the JS Agent without changing them. See [JS Agent error handling](https://docs.fingerprint.com/reference/js-agent-v4-error-handling) for more details.
The `getData` function throws errors directly from the JS Agent without changing them. See [JS Agent error handling](https://docs.fingerprint.com/reference/js-agent-error-handling) for more details.

## API Reference

Expand Down
69 changes: 49 additions & 20 deletions contributing.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
# Contributing to Fingerprint React integration
# Contributing to Fingerprint React SDK

## Working with code

We prefer using [pnpm](https://pnpm.io/) for installing dependencies and running scripts.
We use [pnpm](https://pnpm.io/) for installing dependencies and running scripts.

The main branch is locked for the push action. For proposing changes, use the standard [pull request approach](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request). It's recommended to discuss fixes or new functionality in the Issues, first.
The main branch is locked for the push action. For proposing changes, use the standard [pull request approach](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request). It's recommended to discuss fixes or new functionality in the Issues first.

### Development playground
### How to build

There are 4 demo pages for this integration:
Just run:

1. In `/examples/create-react-app` folder. It is a rich demo with scenarios of using different caching strategies. You can find more info about configuration and starting demo in the [readme](examples/create-react-app/README.md).
2. In `/examples/next` folder. It is a demo built with NextJS that allows testing SSR scenarios. You can find more info about configuration and starting demo in the [readme](examples/next/README.md).
3. In `/examples/next-appDir` folder. It is the same demo built with NextJS, but with new `app` directory approach. You can find more info about configuration and starting demo in the [readme](examples/next-appDir/README.md).
4. In `/examples/preact` folder. It is a demo built with Preact. You can find more info about configuration and starting demo in the [readme](examples/preact/README.md).
5. In `/examples/webpack-based` folder. It is a simple demo built with raw webpack.
```shell
pnpm install
pnpm build
```

❗ Build projects before testing integration. First build the `@fingerprint/react` package, and then start any of the example apps.
### Development playground

### How to build
Six demo apps are available:

Just run:
1. [`create-react-app`](examples/create-react-app/README.md) — a rich demo covering different caching strategies.
2. [`next`](examples/next/README.md) — a Next.js demo for testing SSR scenarios.
3. [`next-appDir`](examples/next-appDir/README.md) — the same Next.js demo using the `app` directory.
4. [`preact`](examples/preact/README.md) — a Preact demo.
5. [`vite`](examples/vite/README.md) — a Vite demo.
6. [`webpack-based`](examples/webpack-based/README.md) — a demo using raw webpack.

Build the SDK before building or starting an example app. From the repository root, run:

```shell
pnpm build
```

Build an example with `pnpm --filter <package-name> build`, or start it with
`pnpm --filter <package-name> dev`.

For example:
```shell
pnpm --filter vite-example dev
```
### Code style

The code style is controlled by [ESLint](https://eslint.org/) and [Prettier](https://prettier.io/). Run to check that the code style is ok:
Expand All @@ -50,20 +63,36 @@ To run tests you can use IDE instruments or just run:
pnpm test
```

To run tests once with a coverage report:

```shell
pnpm test:coverage
```

To check the distributive TypeScript declarations, build the project and run:

```shell
pnpm test:dts
```

### API reference docs

The API reference is generated from the source with [TypeDoc](https://typedoc.org/). Regenerate it into the (git-ignored) `docs/` folder with:

```shell
pnpm docs
```

### How to publish

The library is automatically released and published to NPM on every push to the main branch if there are relevant changes using [semantic-release](https://github.com/semantic-release/semantic-release) with following plugins:
Releases are managed with [changesets](https://github.com/changesets/changesets).

When you make a change that should be released, add a changeset to your pull request:

```shell
pnpm changeset
```

- [@semantic-release/commit-analyzer](https://github.com/semantic-release/commit-analyzer)
- [@semantic-release/release-notes-generator](https://github.com/semantic-release/release-notes-generator)
- [@semantic-release/changelog](https://github.com/semantic-release/changelog)
- [@semantic-release/npm](https://github.com/semantic-release/npm)
- [@semantic-release/github](https://github.com/semantic-release/github)
This prompts you to select the bump type (`major`, `minor`, or `patch`) and to write a summary that becomes the changelog entry. Commit the generated file in `.changeset/` along with your changes.

The workflow must be approved by one of the maintainers, first.
When PRs with changesets are merged to `main`, the [release workflow](.github/workflows/release.yml) opens (or updates) a "Version Packages" pull request that bumps the version and updates the changelog. Merging that pull request builds the package and publishes it to NPM.
16 changes: 11 additions & 5 deletions examples/create-react-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@ In order to try out this example:
To get the API key:

- Go to Fingerprint Dashboard > [API Keys](https://dashboard.fingerprint.com/api-keys) and find it there.
- If you don't have a Fingerprint account, [sign up for free](https://dashboard.fingerprint.com/signup/).
- If you don't have a Fingerprint account, [sign up for free](https://dashboard.fingerprint.com/signup).

### Installing dependencies

1. Go to the root of the project, install dependencies and build it (`cd ../../ && pnpm install && pnpm build`)
2. Come back to the example folder (`cd examples/create-react-app`) and run `pnpm install`.
From the repository root, install dependencies and build the SDK:

After you've completed all the steps and inserted the API key, you can run:
```shell
pnpm install
pnpm build
```

### `pnpm start`
After setting the API key, start the example:

```shell
pnpm --filter fingerprintjs-react-spa-example dev
```

Runs the app in the development mode.\
Open [http://localhost:3001](http://localhost:3001) to view it in the browser.
3 changes: 2 additions & 1 deletion examples/create-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"typescript": "*"
},
"scripts": {
"start": "PORT=3001 DISABLE_ESLINT_PLUGIN=true react-scripts start",
"dev": "PORT=3001 DISABLE_ESLINT_PLUGIN=true react-scripts start",
"start": "pnpm dev",
"build": "DISABLE_ESLINT_PLUGIN=true react-scripts build"
},
"browserslist": {
Expand Down
18 changes: 12 additions & 6 deletions examples/next-appDir/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@ In order to try out this example:
To get the API key:

- Go to Fingerprint Dashboard > [API Keys](https://dashboard.fingerprint.com/api-keys) and find it there.
- If you don't have a Fingerprint account, [sign up for free](https://dashboard.fingerprint.com/signup/).
- If you don't have a Fingerprint account, [sign up for free](https://dashboard.fingerprint.com/signup).

### Installing dependencies

1. Go to the root of the project, install dependencies and build it (`cd ../../ && pnpm install && pnpm build`)
2. Come back to the example folder (`cd examples/next-appDir`) and run `pnpm install`.
From the repository root, install dependencies and build the SDK:

After you've completed all the steps and inserted the API key, you can run:
```shell
pnpm install
pnpm build
```

### `pnpm dev`
After setting the API key, start the example:

```shell
pnpm --filter next-appDir dev
```

Runs the app in the development mode.\
Open [http://localhost:3002](http://localhost:3002) to view it in the browser.
Open [http://localhost:3003](http://localhost:3003) to view it in the browser.
2 changes: 1 addition & 1 deletion examples/next-appDir/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev --port=3002",
"dev": "next dev --port=3003",
"build": "next build",
"start": "next start",
"lint": "next lint"
Expand Down
16 changes: 11 additions & 5 deletions examples/next/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@ In order to try out this example:
To get the API key:

- Go to Fingerprint Dashboard > [API Keys](https://dashboard.fingerprint.com/api-keys) and find it there.
- If you don't have a Fingerprint account, [sign up for free](https://dashboard.fingerprint.com/signup/).
- If you don't have a Fingerprint account, [sign up for free](https://dashboard.fingerprint.com/signup).

### Installing dependencies

1. Go to the root of the project, install dependencies and build it (`cd ../../ && pnpm install && pnpm build`)
2. Come back to the example folder (`cd examples/next`) and run `pnpm install`.
From the repository root, install dependencies and build the SDK:

After you've completed all the steps and inserted the API key, you can run:
```shell
pnpm install
pnpm build
```

### `pnpm dev`
After setting the API key, start the example:

```shell
pnpm --filter next-example dev
```

Runs the app in the development mode.\
Open [http://localhost:3002](http://localhost:3002) to view it in the browser.
Expand Down
18 changes: 12 additions & 6 deletions examples/preact/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@

In order to try out this example:

1. Create a `.env` file in this directory.
1. Create a `.env` (or `.env.local`) file in this directory.
2. Set the `PREACT_APP_FPJS_PUBLIC_API_KEY` environment variable to the value of your Fingerprint Public API key.

To get the API key:

- Go to Fingerprint Dashboard > [API Keys](https://dashboard.fingerprint.com/api-keys) and find it there.
- If you don't have a Fingerprint account, [sign up for free](https://dashboard.fingerprint.com/signup/).
- If you don't have a Fingerprint account, [sign up for free](https://dashboard.fingerprint.com/signup).

### Installing dependencies

1. Go to the root of the project, install dependencies and build it (`cd ../../ && pnpm install && pnpm build`)
2. Come back to the example folder (`cd examples/preact`) and run `pnpm install`.
From the repository root, install dependencies and build the SDK:

After you've completed all the steps and inserted the API key, you can run:
```shell
pnpm install
pnpm build
```

### `pnpm start`
After setting the API key, start the example:

```shell
pnpm --filter preact-example dev
```

Runs the app in the development mode.\
Open [http://localhost:8080](http://localhost:8080) to view it in the browser.
Expand Down
Loading
Loading