Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@spotify-confidence/sdk

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@spotify-confidence/sdk

  • 0.1.6
  • npm
  • Socket score

Version published
Weekly downloads
325
increased by87.86%
Maintainers
0
Weekly downloads
 
Created
Source

Confidence SDK

JavaScript implementation of the Confidence SDK, enables event tracking and feature flagging capabilities in conjunction wth the OpenFeature Web SDK.

Usage

Adding the dependencies

To add the packages to your dependencies run:

yarn add @spotify-confidence/sdk

Initializing the SDK

Run the Confidence.create function to obtain a root instance of Confidence.

import { Confidence } from '@spotify-confidence/sdk';

const confidence = Confidence.create({
  clientSecret: 'mysecret',
  region: 'eu',
  environment: 'client',
  timeout: 1000,
});

Region

The region option is used to set the region for the network request to the Confidence backend. When the region is not set, the default (global) region will be used. The current regions are: eu and us, the region can be set as follows:

const provider = createConfidenceWebProvider({
  region: 'eu', // or 'us'
  // ... other options
});

Timeout

The timeout option is used to set the timeout for the feature flag resolve network request to the Confidence backend. When the timeout is reached, default values will be returned.

Setting the context

You can set the context manually by using setContext({}):

confidence.setContext({ 'pants-color': 'yellow' });

or obtain a "child instance" of Confidence with a modified context by using withContext({})

const childInstance = confidence.withContext({ 'pants-color': 'blue', 'pants-fit': 'slim' });

At this point, the context of childInstance is 'pants-color': 'blue', 'pants-fit': 'slim' while the context of confidence remains {'pants-color': 'yellow'}.

Event tracking

Use confidence.track() from any Confidence instance to track an event in Confidence. Any context data set on the instance will be appended to the tracking event.

confidence.track('event_name', { 'message-detail1': 'something interesting' });

Auto track

Confidence supports automatically tracking certain things out of the box and supports API's for you to extend that functionality. To automatically track page views, use the following:

import { Confidence, pageViews } from '@spotify-confidence/sdk';
confidence.track(pageViews());

and to automatically track events containing web vitals data, use:

import { Confidence, webVitals } from '@spotify-confidence/sdk';
confidence.track(webVitals());

FAQs

Package last updated on 20 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc