FingerprintJS Pro Angular is an easy-to-use Angular library for FingerprintJS Pro. Example of usage is located in the src folder. This package works with FingerprintJS Pro, it is not compatible with open-source FingerprintJS. You can learn more about the difference between FingerprintJS Pro and open-source FingerprintJS in the official documentation.
Using npm:
npm install @fingerprintjs/ng-fingerprintjs-pro
Using yarn:
yarn add @fingerprintjs/ng-fingerprintjs-pro
In order to identify visitors, you'll need a FingerprintJS Pro account (you can sign up for free). You can learn more about API keys in the official FingerprintJS Pro documentation.
- On your Angular Project, you shall include the
NgFingerprintjsProModule
on your highest level application module. The easiest install mode call theforRoot()
method and pass theloadOptions
withapiKey
. You can specify multiple configuration options. Set a region if you have chosen a non-global region during registration. Please refer to the Regions page.
import { NgModule } from '@angular/core';
import { NgFingerprintjsProModule } from 'ng-fingerprintjs-pro';
// ...
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
NgFingerprintjsProModule.forRoot({loadOptions: {apiKey: 'your-fpjs-public-api-key'}})
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
- Add to your component
NgFingerprintjsProService
provided from DI. Use it methodgetVisitorData()
to identify visitor.
import { Component, OnInit } from '@angular/core';
import { NgFingerprintjsProService } from 'ng-fingerprintjs-pro';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
constructor(private ngFingerprintjsProService: NgFingerprintjsProService) { }
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
visitorId = 'Press "Identify" button to get visitorId';
async onIdentifyButtonClick() : Promise<void> {
const data = await this.ngFingerprintjsProService.getVisitorData();
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
this.visitorId = data.visitorId;
this.extendedResult = data;
}
}
extendedResult
, please pay additional attention to caching strategy.
FingerprintJS Pro uses API calls as the basis for billing. Our best practices strongly recommend using cache to optimise API calls rate. The Library uses the SessionStorage cache strategy by default.
Some fields from the extendedResult (e.g ip
or lastSeenAt
) might change for the same visitor. If you need exact current data, it is recommended to pass ignoreCache=true
inside getData function.
This library uses FingerprintJS Pro agent internally. The documentation for the FingerprintJS Pro agent is available on https://dev.fingerprintjs.com/docs.
The module just initialize FingerprintJS Pro agent with load options, configure caching strategy and provides NgFingerprintjsProService
to DI.
loadOptions: FingerprintJS.LoadOptions
Options for the FingerprintJS JS Pro agent load()
method. Options follow agent's initialisation properties.
cacheLocation?: CacheLocation
Defines which built-in cache mechanism the client should use. Caching options follow properties defined in fingerprintjs-pro-spa repository.
cache?: ICache
Custom cache implementation. Takes precedence over the cacheLocation
property. Caching options follow properties defined in fingerprintjs-pro-spa repository.
cacheTimeInSeconds?: number
Duration in seconds for which data is stored in the cache. Cannot exceed 86_400 (24h) because caching data for longer than 24 hours can negatively affect identification accuracy. Caching options follow properties defined in fingerprintjs-pro-spa repository.
cachePrefix?: string
Custom prefix for localStorage and sessionStorage cache keys. Will be ignored if the cache
is provided. Caching options follow properties defined in fingerprintjs-pro-spa repository.
Method performs identification requests with the FingerprintJS Pro API. The returned object contains information about loading status, errors, and visitor.
getOptions: GetOptions<TExtended>
parameter follows parameters of the FingerprintJS Pro'sget
function.
Method clears cache for current caching strategy.
For support or to provide feedback, please raise an issue on our issue tracker. If you require private support, please email us at oss-support@fingerprintjs.com. If you'd like to have a similar Angular library for the open-source FingerprintJS, consider raising an issue in our issue tracker.
This project is licensed under the MIT license. See the LICENSE file for more info.