Before you start
PageSenseClient is the core interface for running experiments. Everything — activating experiments, tracking goals, evaluating variations — runs through this client. You need to initialise it once before any of that works.
Initialization is async and happens in a single step. The SDK calls the PageSense server, fetches your project settings, and sets up the client. Project settings include:
All FullStack experiments configured in your project.
The current status of each experiment.
Traffic allocation and audience targeting rules.
Method
- const pageSenseClient = await PageSenseClientBuilder.createNewPageSenseClient(
- accountId,
- sdkKey,
- projectName,
- sdkOptions
- );
Parameters
Parameter | Type | Description |
accountId | String | Your PageSense account identifier. |
sdkKey | String | Your environment's SDK key. Find it in SDK Settings on the FullStack project configuration page. |
projectName | String | The PageSense project that holds your experiments. |
sdkOptions | Object | Optional. Configure logging, polling, and request behaviour here. |
What happens under the hood
When createNewPageSenseClient() runs:
The SDK requests project settings from the PageSense server.
It parses the experiment configurations, targeting rules, and traffic allocation.
It initialises and returns the PageSenseClient instance.
From that point, the client is ready to evaluate experiments and track events.
If initialization fails — wrong credentials, network issues, missing config — the SDK returns null or throws an error.
Usage Example
- const { PageSenseClientBuilder } = require('@zoho/pagesense-node-sdk');
- async function initializeSDK() {
- const accountId = "YOUR_ACCOUNT_ID";
- const sdkKey = "YOUR_SDK_KEY";
- const projectName = "YOUR_PROJECT_NAME";
- const sdkOptions = {};
- const pageSenseClient = await PageSenseClientBuilder.createNewPageSenseClient(
- accountId,
- sdkKey,
- projectName,
- sdkOptions
- );
- if (!pageSenseClient) {
- console.error("PageSense SDK initialization failed.");
- return;
- }
- console.log("PageSense SDK initialized successfully.");
- }
- initializeSDK();
A few things to keep in mind
createNewPageSenseClient() is async — always await it or use a Promise chain.
Don't call experiment or tracking APIs before the client is ready.
Handle the failure case — a null return means something went wrong during in it.
We’ve
designed this documentation to guide you every step of the way. If you
need further assistance or have any questions, don’t hesitate to contact
us at
support@zohopagesense.com - we’re always here to help!