Skip to content

Commit

Permalink
Merge pull request #160 from fingerprintjs/fix/deprecated-load-options
Browse files Browse the repository at this point in the history
Fix: mention load and get options in readme
  • Loading branch information
JuroUhlar authored Dec 11, 2024
2 parents 34d3cb1 + 455417c commit 54ddefe
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@ Fingerprint is a device intelligence platform offering 99.5% accurate visitor id

## Table of contents

- [Requirements](#requirements)
- [Installation](#installation)
- [Getting started](#getting-started)
- [Linking and tagging information](#linking-and-tagging-information)
- [Caching strategy](#caching-strategy)
- [Error handling](#error-handling)
- [API Reference](#api-reference)
- [Support and feedback](#support-and-feedback)
- [License](#license)

- [Fingerprint Pro React](#fingerprint-pro-react)
- [Table of contents](#table-of-contents)
- [Requirements](#requirements)
- [Installation](#installation)
- [Getting started](#getting-started)
- [1. Wrap your application (or component) in `<FpjsProvider>`.](#1-wrap-your-application-or-component-in-fpjsprovider)
- [2. Use the `useVisitorData()` hook in your components to identify visitors](#2-use-the-usevisitordata-hook-in-your-components-to-identify-visitors)
- [Linking and tagging information](#linking-and-tagging-information)
- [Caching strategy](#caching-strategy)
- [Error handling](#error-handling)
- [API Reference](#api-reference)
- [Support and feedback](#support-and-feedback)
- [License](#license)

## Requirements

Expand Down Expand Up @@ -73,6 +78,7 @@ To get your API key and get started, see the [Fingerprint Pro Quick Start Guide]
- 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://dev.fingerprint.com/docs/regions) during registration.
- Set `endpoint` and `scriptUrlPattern` if you are using [one of our proxy integrations to increase accuracy](https://dev.fingerprint.com/docs/protecting-the-javascript-agent-from-adblockers) and effectiveness of visitor identification.
- You can use all the [load options](https://dev.fingerprint.com/reference/load-function#load-options) available in the JavaScript agent `load` function.

```jsx
// src/index.js
Expand Down Expand Up @@ -143,6 +149,8 @@ The `useVisitorData` hook also returns a `getData` method you can use to make an
- You can pass `{ ignoreCache: true }` to `useVisitorData` to force a fresh identification request.
- You can pass `{ immediate: false }` to `useVisitorData` to disable automatic visitor identification on render.

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

```jsx
// src/App.js
import React, { useState } from 'react'
Expand Down Expand Up @@ -221,6 +229,7 @@ function App() {
Fingerprint Pro usage is billed per API call. To avoid unnecessary API calls, it is a good practice to cache identification results. By default, the SDK uses `sessionStorage` to cache results.

- Specify the `cacheLocation` prop on `<FpjsProvider>` to instead store results in `memory` or `localStorage`. Use `none` to disable caching completely.
- Specify the `cacheTimeInSeconds` prop on `<FpjsProvider>` to set the cache time in seconds. It cannot exceed 86400 seconds (24 hours).
- Specify the `cache` prop on `<FpjsProvider>` to use your custom cache implementation instead. For more details, see [Creating a custom cache](https://github.com/fingerprintjs/fingerprintjs-pro-spa#creating-a-custom-cache)
in the Fingerprint Pro SPA repository (a lower-level Fingerprint library used by this SDK).
- Pass `{ignoreCache: true}` to the `getData()` function to ignore cached results for that specific API call.
Expand Down
4 changes: 2 additions & 2 deletions src/components/fpjs-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import type { EnvDetails } from '../env.types'

const pkgName = packageInfo.name.split('/')[1]

interface CustomAgent {
export interface CustomAgent {
load: (options: FingerprintJSPro.LoadOptions) => Promise<FingerprintJSPro.Agent>
}
interface FpjsProviderOptions extends FpjsClientOptions {
export interface FpjsProviderOptions extends FpjsClientOptions {
/**
* If set to `true`, will force FpjsClient to be rebuilt with the new options. Should be used with caution
* since it can be triggered too often (e.g. on every render) and negatively affect performance of the JS agent.
Expand Down
4 changes: 2 additions & 2 deletions src/fpjs-context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext } from 'react'
import { VisitorData, GetOptions } from '@fingerprintjs/fingerprintjs-pro-spa'
import { VisitorData, GetOptions, FingerprintJSPro } from '@fingerprintjs/fingerprintjs-pro-spa'

export interface QueryResult<TData, TError = Error> {
/**
Expand All @@ -20,7 +20,7 @@ export interface VisitorQueryResult<TExtended extends boolean> extends QueryResu
data?: VisitorData<TExtended>
}

export interface GetDataOptions<TExtended extends boolean> extends GetOptions<TExtended> {
export interface GetDataOptions<TExtended extends boolean> extends FingerprintJSPro.GetOptions<TExtended> {
/**
* When set to true, the visitor data will always be fetched from our API.
* */
Expand Down
7 changes: 5 additions & 2 deletions src/use-visitor-data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FpjsContextInterface, FpjsContext, GetDataOptions, QueryResult, VisitorQueryContext } from './fpjs-context'
import { useCallback, useContext, useEffect, useState } from 'react'
import { GetOptions, VisitorData } from '@fingerprintjs/fingerprintjs-pro-spa'
import { VisitorData, FingerprintJSPro } from '@fingerprintjs/fingerprintjs-pro-spa'
import { usePrevious } from './utils/use-previous'
import deepEquals from 'fast-deep-equal'
import { toError } from './utils/to-error'
Expand Down Expand Up @@ -50,7 +50,10 @@ export function useVisitorData<TExtended extends boolean>(

const { ignoreCache: defaultIgnoreCache, ...getVisitorDataOptions } = getOptions

const getDataOptions: GetOptions<TExtended> = { ...getVisitorDataOptions, ...getDataPassedOptions }
const getDataOptions: FingerprintJSPro.GetOptions<TExtended> = {
...getVisitorDataOptions,
...getDataPassedOptions,
}

const result = await getVisitorData(
getDataOptions,
Expand Down

0 comments on commit 54ddefe

Please sign in to comment.