# TWIPLA Worker
Integrates with [TWIPLA - The Website Intelligence Platform](https://www.twipla.com)

# 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/worker
```

# Usage examples

## ESM
```typescript
import { LogLevel, TwiplaWorker } from '@twipla/worker';

const twiplaWorker = new TwiplaWorker({
  websiteId: 'your_website_id',
  logLevel: LogLevel.ERROR,
  env: 'production'
});
```
or
```html
<script type="module">
  import { TwiplaWorker, LogLevel } from 'https://cdn.jsdelivr.net/npm/@twipla/worker@0.1.0-rc.14/lib/esm/library.js';

  const twiplaWorker = new TwiplaWorker({
    websiteId: 'your_website_id',
    logLevel: LogLevel.ERROR,
    env: 'production'
  });
</script>
```


## IIFE
```html
<script src="https://cdn.jsdelivr.net/npm/@twipla/worker@0.1.0-rc.14/lib/iife/library.js"></script>
<script>
  const twiplaWorker = new Twipla.TwiplaWorker({
    websiteId: 'your_website_id',
    logLevel: Twipla.LogLevel.ERROR,
    env: 'production'
  });
</script>
```

## CJS
```typescript
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
```typescript
// without optional parameters
twiplaWorker.run();

// with optional parameters
twiplaWorker.run({ tags: { key: 'value' } });
```

## Track an event
```typescript
twiplaWorker.sendEvent('event_category', 'event_action', 'event_label', 'event_value', 'event_extra_fields')
```

## Track an ecommerce event
```typescript
twiplaWorker.sendEcom('','','')
```
