browser-identity
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

Using the browser-identity package

The browser-identity package is used to retrieve a visitor id related to the user's browser or environment.

Usage

Functions

getVisitorId This function takes one argument of type SourcesToComponents and returns a string, which represents the visitor identifier.

Usage

import { getVisitorId } from 'browser-identity';

const visitorId = getVisitorId(yourAttributes);
console.log(visitorId); // This will log the visitor identifier.

getVisitorData

This function takes one argument of type SourcesToComponents<typeof sources> and returns a Promise of type Agent, which includes various properties related to the visitor.

Usage

import { getVisitorData } from 'browser-identity';

getVisitorData(yourAttributes)
  .then((agent) => {
    console.log(agent.visitorId); // Visitor Identifier
    console.log(agent.confidence); // Confidence Score
    console.log(agent.attributes); // List of Components
  })
  .catch((error) => {
    console.error(error); // Handle any errors that occur during the retrieval of visitor data.
  });

The Agent interface represents the visitor's data and has the following properties:

  • visitorId: The visitor identifier.
  • confidence: A confidence score that indicates how certain the agent is about the visitor identifier.
  • attributes: A list of components that have formed the visitor identifier. Note that the type of this property may have incompatible changes within a major version.

The BuiltInComponents object contains various components and their corresponding values and durations. These components represent different aspects of the visitor's environment.

Here are some examples of the components included in BuiltInComponents:

  • applePay
  • architecture
  • audio
  • canvas
  • colorDepth
  • colorGamut
  • contrast
  • cookiesEnabled
  • cpuClass
  • deviceMemory
  • domBlockers
  • fontPreferences
  • fonts
  • forcedColors
  • hardwareConcurrency
  • hdr
  • indexedDB
  • invertedColors
  • languages
  • localStorage
  • math
  • monochrome
  • openDatabase
  • osCpu
  • pdfViewerEnabled
  • platform
  • plugins
  • privateClickMeasurement
  • reducedMotion
  • screenFrame
  • screenResolution
  • sessionStorage
  • timezone
  • touchSupport

Each component has a value and duration associated with it, which represents its value and how long it took to collect that data.

Please note that this is a general overview of how to use these functions and interfaces with the browser-identity package. You should refer to the specific documentation of the browser-identity package for more detailed information and any additional configuration or usage instructions.

Package Sidebar

Install

npm i browser-identity

Weekly Downloads

0

Version

1.2.0

License

MIT

Unpacked Size

173 kB

Total Files

98

Last publish

Collaborators

  • sophanna