@twipla/worker
v1.8.1
Published
TWIPLA Standalone Worker
Downloads
982
Keywords
Readme
TWIPLA Worker
Integrates with TWIPLA - The Website Intelligence Platform
Variants
The TWIPLA Worker comes in 2 variants:
full- this is the default version, including all TWIPLA worker features (polls, heatmap screenshots, autotracking previewer, etc.)core- this is the lightest version possible, containing only core functionality: visits and recordings
The interface is the same, the only exception being the fact that the core version should be imported from @twipla/worker/core.
Installation
npm install @twipla/workerUsage examples
ESM
import { LogLevel, TwiplaWorker } from '@twipla/worker';
const twiplaWorker = new TwiplaWorker({
websiteId: 'your_website_id',
logLevel: LogLevel.ERROR,
env: 'production'
});or
<script type="module">
import { TwiplaWorker, LogLevel } from 'https://cdn.jsdelivr.net/npm/@twipla/[email protected]/lib/esm/library.js';
const twiplaWorker = new TwiplaWorker({
websiteId: 'your_website_id',
logLevel: LogLevel.ERROR,
env: 'production'
});
</script>IIFE
<script src="https://cdn.jsdelivr.net/npm/@twipla/[email protected]/lib/iife/library.js"></script>
<script>
const twiplaWorker = new Twipla.TwiplaWorker({
websiteId: 'your_website_id',
logLevel: Twipla.LogLevel.ERROR,
env: 'production'
});
</script>CJS
const { TwiplaWorker, LogLevel } = require('@twipla/worker/lib/cjs/library.js');
const twiplaWorker = new TwiplaWorker({
websiteId: 'your_website_id',
logLevel: Twipla.LogLevel.ERROR,
env: 'production'
});Track a visit
// without optional parameters
twiplaWorker.run();
// with optional parameters
twiplaWorker.run({ tags: { key: 'value' } });Metadata
Metadata attaches structured content information to a visit. It is passed to run() and is automatically sent alongside the visit payload.
twiplaWorker.run({
metadata: {
type: 'post',
authors: [{ id: 72145, name: 'John Doe' }],
blocks: [
{ name: 'core/paragraph', count: 28 },
{ name: 'core/heading', count: 4 },
{ name: 'core/image', count: 1 }
],
categories: [{ id: 60, slug: 'news', name: 'News' }],
tags: [{ id: 72011, slug: 'weather-june', name: 'Weather June' }]
}
});Track an event
twiplaWorker.sendEvent('event_category', 'event_action', 'event_label', 'event_value', 'event_extra_fields');Track an ecommerce event
twiplaWorker.sendEcom('', '', '');