Leverage cookies

In additional to the ChainvineClient operations, we offer a few global utility methods to assist in keeping track of referrals through the use of cookies.

Note: these operations rely on browser functionality and will throw an error if used in a non-browser context

Storing a Referrer

import { storeReferrer } from '@chainvine/sdk';

// Fetches the "r" query parameter from the URL (if available)
// and stores it in a CV_REF cookie with an expiration of 120 days

Should you already have a reference to he referrer's ID or if you would like to adjust the cookies expiration you may do so by providing overrides as below:

  durationDays: 30, //Override the default cookie duration (120 days)
  referrer: 'ABC123', //Should you already have access to the referrer, and if you do not want it fetched from the URL, you can provide it directly

Fetching a stored Referrer

Once you've stored the referrer, you can access it at any point in your application like so:

import { getReferrer } from '@chainvine/sdk';

const referrer = getReferrer();

Clearing the stored Referrer

The referrer cookie can be cleared at any point using the following operation:

import { clearReferrer } from '@chainvine/sdk';


Last updated