Client side Tracking
In client-side tracking, we discuss how to use qwestive-client-sdk npm package which handles tracking payload generation and sends requests from browser to Qwestive backend.
π Table of Contents
π§ About
Qwestive client sdk is a npm package that can be used to register invitees
π Getting Started
These instructions will get you started with the project up and running on your local machine for development.
Prerequisites
node: v16.20.0
npm: 8.19.4
yarn: 1.22.19
Installation
Any of the below ways can be used to add the package to your existing web app
NPM
npm install qwestive-client-sdk
Yarn
yarn add qwestive-client-sdk
Browser
<script src="https://unpkg.com/[email protected]/dist/index.js"></script>
π Usage
import QwestiveClientSDK from 'qwestive-client-sdk';
async function testQwestiveClientSDK() {
const qwestiveClient = new QwestiveClientSDK(
QWESTIVE_REFERRAL_PROJECT_ID,
QWESTIVE_REFERRAL_API_KEY,
);
await qwestiveClient.init();
await qwestiveClient.setReferral({
publicKey: '0x71C7656EC7ab88b098defB751B7401B5f6d8976F'
});
}
testQwestiveClientSDK();
Initializing the SDK
Initialize the SDK with API KEY
and projectId
(checkout developers section to know how to find these)
Initializing the SDK authenticates the client and validates client's domain against
whitelisted domains
added from project settings.Returns the available
campaignConfig
andisRegisteredInvitee
const {campaignConfig, isRegisteredInvitee} = await qwestiveClient.init();
campaignConfig
{
showPopup: boolean;
textColor: string;
backgroundColor: string;
buttonColor: string;
buttonText: string;
buttonTextColor: string;
text: string;
title: string;
}
This refers to the UI config of the campaign that can be used to show popup card.
isRegisteredInvitee
boolean
This denotes whether the current user is registered invitee or not in the campaign.
Send setReferral event
This method should be triggered when the invitee connects the wallet on your Dapp.
Sets the current user as the registered invitee in the campaign
const { publicKey, isRegisteredInvitee } = await qwestiveClient.setReferral({
// user's wallet public key
publicKey: string,
})
publicKey
string
The users wallet public key.
isRegisteredInvitee?
boolean
This denotes whether the current user is a registered invitee. This is only returned if the user is already a registered invitee. Otherwise it will not be sent.
Testing
Make sure, SDK instance is initialized like mentioned in the documentation above.
Generate referral code:
go to referral.qwestive.io and select your project
go to referral section from left sidebar and select your campaign
from campaign page, generate referral link and copy referral code
while local development, use it like http://localhost:3000/?qwest=4266W to simulate referral link flow
If using
localhost
shows unauthorized domain, then consider adding locahost along with port as whitelisted domain in project settings
If you don't see any errors on console, check the campaign page which index referrals every 3-4 minutes
If you are able to spot new referrals in invitees table and sent off-chain events in the activity table, then we have correctly integrated the Tracking SDK, cheers!
Otherwise, reach out to us for help.
Demo
Setup qwestive-client-sdk
Checking data on dashboard to check if integration was successful
Last updated