@fingerprintjs/fingerprintjs-pro-vue-v3

中文文档
1.5.0发布于 2024/03/25MITTypeScriptESM + CJS近 30 天下载 1.2万

Fingerprint Pro Plugin for Vue v3

原始使用文档
文档目录13 节
  1. Requirements
  2. Installation
  3. Getting started
  4. Composition API
  5. Options API
  6. Mixins
  7. Nuxt
  8. Linking and tagging information
  9. Documentation
  10. Caching strategy
  11. Support and feedback
  12. Examples
  13. License

Fingerprint logo

Build status Release status Current NPM version Monthly downloads from NPM MIT license Discord server

Fingerprint Pro Vue 3 SDK

Fingerprint is a device intelligence platform offering 99.5% accurate visitor identification.

Fingerprint Pro Vue SDK is an easy way to integrate Fingerprint Pro into your Vue 3 application. It supports all capabilities of the Fingerprint JavaScript agent and provides a built-in caching mechanism.

Requirements

  • For Typescript users: Typescript 4.5 or higher
  • Vue 3.1 or higher
  • For Nuxt users: Nuxt 3.0 or higher

This package works with Fingerprint Pro, it is not compatible with source-available FingerprintJS. See our documentation to learn more about the difference between Fingerprint Pro and the source-available FingerprintJS.

⚠️ We no longer provide SDK for Vue2, due to the end of support. We recommend upgrading to Vue 3.

Installation

To install the plugin run:

yarn add @fingerprintjs/fingerprintjs-pro-vue-v3

Or:

npm install @fingerprintjs/fingerprintjs-pro-vue-v3
pnpm add @fingerprintjs/fingerprintjs-pro-vue-v3

Getting started

To identify visitors, you'll need a Fingerprint Pro account (you can sign up for free). Get your API key and get started with the Fingerprint Pro documentation.

Register our plugin in your Vue application.

  • Set a region if you have chosen a non-global region during registration.
  • Set endpoint and scriptUrlPattern if you are using one of our proxy integrations to increase the accuracy and effectiveness of visitor identification.
import { createApp } from 'vue';
import App from './App.vue';
import {
  fpjsPlugin,
  FpjsVueOptions,
  // defaultEndpoint,
  // defaultScriptUrlPattern,
} from '@fingerprintjs/fingerprintjs-pro-vue-v3';

const app = createApp(App);

const apiKey = '<public-api-key>'

app
  .use(fpjsPlugin, {
    loadOptions: {
      apiKey: '<your-public-api-key>',
      // region: 'eu',
      // endpoint: ['metrics.yourwebsite.com', defaultEndpoint],
      // scriptUrlPattern: ['metrics.yourwebsite.com/agent-path', defaultScriptUrlPattern],
    },
  } as FpjsVueOptions)
  .mount('#app');

You can use the plugin with Composition API, Options API, or Mixins, with or without Nuxt. See the usage examples below.

Composition API

The plugin provides a useVisitorData function you can use to identify visitors:

<script setup>
import { useVisitorData } from '@fingerprintjs/fingerprintjs-pro-vue-v3';
import { watch } from 'vue';

const { data, error, isLoading, getData } = useVisitorData(
  { extendedResult: true }, 
  // Set to true to fetch data on mount
  { immediate: false }
);

watch(data, (currentData) => {
  if (currentData) {
    // Do something with the data
  }
});
</script>

<template>
  <button @click='getData'>Get visitor data</button>
</template>

Options API

The plugin injects a $fpjs object into your components that you can use to identify visitors:


<script lang='ts'>
import { defineComponent } from 'vue';

export default defineComponent({
  methods: {
    async getVisitorData() {
      const visitorData = await this.$fpjs.getVisitorData({
        extendedResult: true
      });

      // Do something with visitorData
    }
  }
});
</script>

<template>
  <button @click='getVisitorData'>Get visitor data</button>
</template> 

Mixins

For your convenience, we also provide mixins that handle all query states.

For the extended result:


<script lang='ts'>
import { defineComponent } from 'vue';
import { fpjsGetVisitorDataExtendedMixin } from '@fingerprintjs/fingerprintjs-pro-vue-v3';

export default defineComponent({
  // Include our mixin
  mixins: [fpjsGetVisitorDataExtendedMixin],
  async mounted() {
    // You can also fetch data on mount
    // await this.$getVisitorDataExtended();
  }
});
</script>

<template>
  <div>
    <button @click='$getVisitorDataExtended'>
      Get visitor data
    </button>
    <span v-if='visitorDataExtended.isLoading'>
      Loading...
    </span>
    <span v-else-if='visitorDataExtended.isError'>
      Error: {{ visitorDataExtended.error }}
    </span>
    <span v-else>
      <!--Do something with visitorData here-->
    </span>
  </div>
</template>

For the default result:


<script lang='ts'>
import { defineComponent } from 'vue';
import { fpjsGetVisitorDataMixin } from '@fingerprintjs/fingerprintjs-pro-vue-v3';

export default defineComponent({
  // Include our mixin
  mixins: [fpjsGetVisitorDataMixin],
  async mounted() {
    // You can also fetch data on mount
    // await this.$getVisitorData();
  }
});
</script>

<template>
  <div>
    <button @click='$getVisitorData'>
      Get visitor data
    </button>
    <span v-if='visitorData.isLoading'>
      Loading...
    </span>
    <span v-else-if='visitorData.isError'>
      Error: {{ visitorData.error }}
    </span>
    <span v-else>
      <!--Do something with visitorData here-->
    </span>
  </div>
</template>

Nuxt

The plugin works with Nuxt out of the box, however, you need to register it on the client side only.

// plugins/fingerprintjs.client.ts
import { defineNuxtPlugin, useRuntimeConfig } from '#app';
import {
  fpjsPlugin,
  FpjsVueOptions,
  // defaultEndpoint,
  // defaultScriptUrlPattern,
} from '@fingerprintjs/fingerprintjs-pro-vue-v3';

export default defineNuxtPlugin((nuxtApp) => {
  const config = useRuntimeConfig();

  nuxtApp.vueApp.use(fpjsPlugin, {
    loadOptions: {
      apiKey: config.public.API_KEY,
      // region: 'eu',
      // endpoint: ['metrics.yourwebsite.com', defaultEndpoint],
      // scriptUrlPattern: ['metrics.yourwebsite.com/agent-path', defaultScriptUrlPattern],
    },
  } as FpjsVueOptions);
});
//nuxt.config.ts

import { defineNuxtConfig } from 'nuxt';
import path from 'path';

export default defineNuxtConfig({
  runtimeConfig: {
    public: {
      // Inject Fingerprint Pro API key
      API_KEY: process.env.API_KEY,
    },
  }
});

See the example Nuxt Application for more details.

Linking and tagging information

The visitorId provided by Fingerprint Identification is especially useful when combined with information you already know about your users, for example, account IDs, order IDs, etc. To learn more about various applications of the linkedId and tag, see Linking and tagging information.

Associate your data with a visitor ID using the linkedId or tag parameter of the options object passed into the useVisitorData() hook or the getData function:

<script setup>
 import { useVisitorData } from '@fingerprintjs/fingerprintjs-pro-vue-v3';

 const { data, error, isLoading, getData } = useVisitorData({
  linkedId: 'user_1234',
  tag: {
   userAction: 'login',
   analyticsId: 'UA-5555-1111-1',
  },
 })
</script>

<template>
<!--...-->
</template>

Documentation

You can find detailed documentation in the API reference.

Caching strategy

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 cacheLocation in FpjsVueOptions to instead store results in memory or localStorage. Use none to disable caching completely.
  • Specify cache in FpjsVueOptions to use your custom cache implementation instead. For more details, see 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()/getVisitorData()/getVisitorDataExtended() function to ignore cached results for that specific API call.

[!NOTE] If you use data from extendedResult, pay additional attention to your caching strategy. Some fields, for example, ip or lastSeenAt, might change over time for the same visitor. Use getData({ ignoreCache: true }) to fetch the latest identification results.

Support and feedback

To ask questions or provide feedback, use Issues. If you need private support, please email us at [email protected]. If you'd like to have a similar Vue wrapper for the open-source FingerprintJS, consider creating an issue in the main FingerprintJS repository.

Examples

You can find the following examples in the examples directory:

License

This project is licensed under the MIT license.

版本与发布记录

@fingerprintjs/fingerprintjs-pro-vue-v3 共发布 16 个版本,首次发布于 2022/06/13;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.5.0latest2024/03/252 年前
1.4.1-test.2test2024/03/202 年前
1.4.1-test.12024/03/202 年前
1.4.02023/10/113 年前
1.3.12023/10/053 年前
1.3.02023/09/203 年前

关于 @fingerprintjs/fingerprintjs-pro-vue-v3 的常见问题

@fingerprintjs/fingerprintjs-pro-vue-v3 是什么?

Fingerprint Pro Plugin for Vue v3

如何安装 @fingerprintjs/fingerprintjs-pro-vue-v3?

在项目目录运行 npm install @fingerprintjs/fingerprintjs-pro-vue-v3,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vue(^3.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@fingerprintjs/fingerprintjs-pro-vue-v3 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@fingerprintjs/fingerprintjs-pro-vue-v3 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@fingerprintjs/fingerprintjs-pro-vue-v3 可以商用吗?

@fingerprintjs/fingerprintjs-pro-vue-v3 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fingerprintjs/fingerprintjs-pro-vue-v3 的下载量有多少?

根据 npm 官方下载统计,@fingerprintjs/fingerprintjs-pro-vue-v3 在 2026/10/15 – 2026/11/13 这 30 天内被下载 11,662 次,日均约 389 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fingerprintjs/fingerprintjs-pro-vue-v3 还在维护吗?

最新版本 1.5.0 发布于 2024/03/25(2 年前);至今共发布 16 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/06/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。