Skip to content

Commit

Permalink
Return the monitoring option documentation (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
Finesse authored Nov 27, 2023
1 parent 5d6544f commit 797b60a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
12 changes: 11 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ A request includes the following information:
- The HTTP headers that the client sends, including the origin and the referrer of the page where the library runs
- The IP of the client

You can turn off these requests by using the `monitoring` option:

```diff
const botdPromise = BotD.load({
+ monitoring: false
})
```

💡 Scripts downloaded from our CDN (https://openfpcdn.io) have monitoring disabled by default.

### CommonJS syntax:

```js
Expand All @@ -67,7 +77,7 @@ load()

## API

#### `BotD.load(): Promise<BotDetector>`
#### `BotD.load({ monitoring?: boolean }): Promise<BotDetector>`

Builds an instance of `BotDetector`. We recommend calling it as early as possible,
ideally during application startup. It returns a promise which you can chain on to call `BotDetector` methods later.
Expand Down
15 changes: 13 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ import { detectors } from './detectors'
import { BotdError, BotDetectorInterface, BotKind, BotDetectionResult } from './types'
import { collect, detect } from './api'

/**
* Options for BotD loading
*/
export interface LoadOptions {
/**
* Set `false` to disable the unpersonalized AJAX request that the agent sends to collect installation statistics.
* It's always disabled in the version published to the FingerprintJS CDN.
*/
monitoring?: boolean
}

/**
* Sends an unpersonalized AJAX request to collect installation statistics
*/
Expand All @@ -24,8 +35,8 @@ function monitor() {
}
}

export async function load(options?: Record<keyof any, any>): Promise<BotDetectorInterface> {
if (options?.monitoring ?? true) {
export async function load({ monitoring = true }: Readonly<LoadOptions> = {}): Promise<BotDetectorInterface> {
if (monitoring) {
monitor()
}
const detector = new BotDetector()
Expand Down

0 comments on commit 797b60a

Please sign in to comment.