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

@rudderstack/analytics-js-cookies

Package Overview
Dependencies
Maintainers
0
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rudderstack/analytics-js-cookies

RudderStack JavaScript SDK Cookies Utilities

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
430
decreased by-14.17%
Maintainers
0
Weekly downloads
 
Created
Source

TypeScript

RudderStack
The Customer Data Platform for Developers

Website · Documentation · Community Slack


@rudderstack/analytics-js-cookies

RudderStack JavaScript SDK utility for cookies.

APIs

getDecryptedValue

This function decrypts the provided encrypted RudderStack JavaScript cookie value using the RudderStack JavaScript SDK encryption version "v3".

The encrypted value should be a string starting with RS_ENC_v3_.

If the provided value is not properly encrypted, the function will throw an exception.

import { decrypt } from '@rudderstack/analytics-js-cookies';

const encryptedCookieValue = 'RS_ENC_v3_InRlc3QtZGF0YSI=';
const decryptedCookieValue = decrypt(encryptedCookieValue);
console.log('Decrypted Cookie Value: ', decryptedCookieValue);
// Output: Decrypted Cookie Value: test-data

getDecryptedCookie

This function decrypts and returns the RudderStack JavaScript SDK cookie values.

The return type is either a string or an object as some cookies like user ID, anonymous user ID have string values while user traits are objects.

It returns null in either of the following scenarios:

  • If the cookie is not present.
  • If the cookie is not properly encrypted.
    • It only decrypts the cookies that are created by the RudderStack JavaScript SDK encryption version "v3".
  • If the decrypted cookie value is not a valid JSON string.
  • If the provided cookie name is not a valid RudderStack JavaScript SDK cookie name.

Any errors during decryption are swallowed by the function, returning null.

The following are the available cookie key exports:

  • userIdKey: The key for the user ID cookie.
  • userTraitsKey: The key for the user traits cookie.
  • anonymousUserIdKey: The key for the anonymous user ID cookie.
  • groupIdKey: The key for the group ID cookie.
  • groupTraitsKey: The key for the group traits cookie.
  • pageInitialReferrerKey: The key for the page initial referrer cookie.
  • pageInitialReferringDomainKey: The key for the page initial referring domain cookie.
  • sessionInfoKey: The key for the session ID cookie.
  • authTokenKey: The key for the auth token cookie.
import {
  getDecryptedCookie,
  anonymousUserIdKey,
  userTraitsKey,
} from '@rudderstack/analytics-js-cookies';

const anonymousId = getDecryptedCookie(anonymousUserIdKey);
console.log('Anonymous User ID: ', anonymousId);
// Output: Anonymous User ID: 2c5b6d48-ea90-43a2-a2f6-457d27f90328

const userTraits = getDecryptedCookie(userTraitsKey);
console.log('User Traits: ', userTraits);
// Output: User Traits: {"email":"abc@xyz.com","name":"John Doe"}

const invalidCookie = getDecryptedCookie('invalid-cookie-name');
console.log('Invalid Cookie: ', invalidCookie);
// Output: Invalid Cookie: null

For detailed documentation on the RudderStack JavaScript SDK, click here.

Keywords

FAQs

Package last updated on 25 Jun 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