SDK Integration Guide

Prerequisites

Before you begin, ensure you have the following:

  • **An API Key:** You'll need an API key to authenticate your application with our service. You can find this in your project settings.
  • **An Application to Integrate:** This guide assumes you have a basic web application where you want to track events.
Step 1: Install the SDK

The easiest way to get started is by installing our package from npm. Open your terminal in your project's root directory and run the following command:

npm install @your-company/analytics-sdk
Step 2: Initialize the SDK

Once installed, you can initialize the SDK in your application's entry point (e.g., `App.js` or `index.js`). It's best to do this once when your application first loads.

**Important:** Replace `"YOUR_API_KEY"` with your actual API key.

import AnalyticsSDK from '@your-company/analytics-sdk';

// Initialize the SDK with your API key
const sdk = new AnalyticsSDK({
  apiKey: "YOUR_API_KEY"
});

// Make the sdk instance globally available or pass it via context
export default sdk;
Step 3: Track Events

With the SDK initialized, you can start tracking key user actions. The `track` method is the primary function for sending events. It accepts two arguments: the event name (a string) and an optional payload of properties (an object).

Tracking Page Views

import sdk from './sdk';
import { useEffect } from 'react';

function MyPage() {
  useEffect(() => {
    sdk.track("Page Viewed", {
      path: window.location.pathname,
      title: document.title
    });
  }, []);

  return (
    // Your page content
  );
}

Tracking Button Clicks

import sdk from './sdk';

function HeroSection() {
  const handleHeroButtonClick = () => {
    sdk.track("Hero: Main CTA Clicked", {
      button_text: "Get Started Now",
      location: "Hero Section"
    });
    window.location.href = "/get-started";
  };

  return (
    <button onClick={handleHeroButtonClick}>
      Get Started Now
    </button>
  );
}
Verification

After you've integrated the SDK and deployed your changes, you should be able to see the events appear in your dashboard.