thrivestack-node-sdk
Version:
Official ThriveStack Analytics SDK for Node.js and Next.js server-side applications
57 lines • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const ThriveStack_1 = require("./ThriveStack");
async function example() {
// Initialize ThriveStack with your API key
const thriveStack = new ThriveStack_1.ThriveStack({
apiKey: "/0h1H3frdqN8u1C99q03MMu+VO8YbQeXbNa1VQPXf3A=",
source: "marketing,product",
batchSize: 5,
batchInterval: 1000,
enableConsent: true
});
// Initialize the SDK
await thriveStack.init('user123', 'example-source');
// Enable debug mode to see what's being sent
thriveStack.enableDebugMode();
// Set consent for different tracking categories
thriveStack.setConsent('functional', true);
thriveStack.setConsent('analytics', true);
thriveStack.setConsent('marketing', false);
// Capture a page visit event
await thriveStack.capturePageVisit({
title: 'Example Page',
url: 'https://example.com/page',
path: '/page',
referrer: 'https://google.com'
});
// Capture a custom event
await thriveStack.captureEvent('button_click', {
button_id: 'submit-btn',
button_text: 'Submit',
page_section: 'form'
});
// Set user information
await thriveStack.setUser('user123', 'user@example.com', {
first_name: 'John',
last_name: 'Doe',
company: 'Example Corp'
});
// Set group information
await thriveStack.setGroup('group456', 'example.com', 'Example Corporation', {
industry: 'Technology',
size: '100-500'
});
// Get current configuration
const config = thriveStack.getConfig();
console.log('Current configuration:', config);
// Get interaction history
const history = thriveStack.getInteractionHistory();
console.log('Interaction history:', history);
// Get device and session IDs
console.log('Device ID:', thriveStack.getDeviceId());
console.log('Session ID:', thriveStack.getSessionId());
}
// Run the example
example().catch(console.error);
//# sourceMappingURL=example.js.map