Skip to main content

JavaScript SDK

The Linquid JavaScript SDK provides easy conversion tracking for web applications.

Installation

CDN

<script src="https://cdn.linquid.io/pixel.js"></script>

NPM

npm install @linquid/pixel
import { linquid } from '@linquid/pixel';

Quick Start

// Initialize with your campaign pixel code
linquid.init('lw_px_your_pixel_code');

// Track a conversion
linquid.track('purchase', {
  value: 99.99,
  currency: 'USD'
});

Methods

init(pixelCode, options)

Initialize the SDK:
linquid.init('lw_px_xxx', {
  debug: false,      // Enable console logging
  autoTrack: true    // Auto-track page views
});

track(event, properties)

Track a conversion event:
linquid.track('signup', {
  plan: 'pro',
  method: 'google'
});

getClickId()

Get the current click ID:
const clickId = linquid.getClickId();
// "lw_ck_abc123" or null

pageview()

Track a page view (for SPAs):
linquid.pageview();

Event Examples

Purchase

linquid.track('purchase', {
  value: 149.98,
  currency: 'USD',
  orderId: 'ORD-12345',
  items: [
    { sku: 'PROD-1', price: 49.99, quantity: 2 },
    { sku: 'PROD-2', price: 50.00, quantity: 1 }
  ]
});

Signup

linquid.track('signup', {
  method: 'email',
  plan: 'free'
});

Lead

linquid.track('lead', {
  source: 'contact_form',
  interest: 'demo'
});

SPA Integration

React

import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';

function App() {
  const location = useLocation();

  useEffect(() => {
    linquid.pageview();
  }, [location.pathname]);

  return <Routes />;
}

Next.js

// pages/_app.js
import { useEffect } from 'react';
import { useRouter } from 'next/router';

function MyApp({ Component, pageProps }) {
  const router = useRouter();

  useEffect(() => {
    const handleRouteChange = () => linquid.pageview();
    router.events.on('routeChangeComplete', handleRouteChange);
    return () => router.events.off('routeChangeComplete', handleRouteChange);
  }, [router.events]);

  return <Component {...pageProps} />;
}

Debug Mode

Enable debug mode for development:
linquid.init('lw_px_xxx', { debug: true });
This logs all tracking calls to the console.

TypeScript

The SDK includes TypeScript definitions:
import { linquid, TrackEvent } from '@linquid/pixel';

const event: TrackEvent = {
  value: 99.99,
  currency: 'USD'
};

linquid.track('purchase', event);