Server-side SDKs

Scoby Analytics Typescript SDK

Welcome to the Scoby Analytics TypeScript SDK documentation. This guide will help TypeScript developers integrate and utilize our analytics tool effectively.

Prerequisites

You need your License Key and Salt to use our Typescript SDK.

Installation

Begin by adding the SDK to your TypeScript project from the NPM registry:

npm install @scoby/analytics-ts --save

or if you're using Yarn:

yarn add @scoby/analytics-ts

Usage

Initialization

Start by importing and initializing the Scoby Analytics client:

import { Client } from '@scoby/analytics-ts';

const API_KEY: string = 'INSERT_YOUR_API_KEY_HERE';
const SALT: string = 'INSERT_YOUR_SALT_HERE';

const client = new Client(API_KEY, SALT);

Logging Page Views

Use the client to asynchronously log page views:

await client.logPageView({
  ipAddress: 'YOUR_IP_ADDRESS',
  requestedUrl: 'YOUR_REQUESTED_URL',
  referringUrl: 'YOUR_REFERRING_URL',
  userAgent: 'YOUR_USER_AGENT'
});

Segmenting Visitors

Segment visitors based on their attributes or behaviors:

await client.logPageView({
  ...
  visitorSegments: ['Segment1', 'Segment2', ...]
});

Remember, to maintain user anonymity, Scoby Analytics implements k-Anonymity of 25 for visitor segments.

Using your own Visitor ID

For improved accuracy in visitor counting, provide a hashed custom identifier:

await client.logPageView({
  ...
  visitorId: 'YOUR_HASHED_VISITOR_ID'
});

Ensure to discuss with your data protection officer before integrating this feature.

IP Blacklisting

If needed, blacklist certain IP ranges. Both wildcard patterns and CIDR subnet notations are supported:

client.blacklistIpRange('12.34.*.*');
...

For instance:

client.blacklistIpRange('12.34.*.*');

await client.logPageView({
  ipAddress: '12.34.56.78',
  ...
}); // will return false due to IP blacklisting

Support

Should you face any challenges, we're here to assist. Please email us at hello@scoby.io.

Previous
Node.js SDK