JavaScript (Web)
Install the Pieowl Web SDK from npm to track page views, events and users in the browser, with TypeScript types.
Installation
Step 1: Install
npm install @pieowl/webStep 2: Initialize
import { Pieowl } from '@pieowl/web';
export const pieowl = new Pieowl({
clientId: 'YOUR_CLIENT_ID',
});clientId is enough. What the SDK collects by itself (page views, outside link clicks, data-track clicks, session replay) is set in Settings → Site → What Pieowl counts, not in code.
Options
Common options
apiUrl- The URL of the Pieowl API (default:https://api.pieowl.com). Change it only to send events through your own proxyclientId- The client id of your applicationclientSecret- The client secret of your application (only required for server-side events)filter- A function that will be called before sending an event. If it returns false, the event will not be sentdisabled- If true, events are queued and not sent until you callready()(useful for consent)
Web options
What the script collects by itself is set per site in Settings → Site → What Pieowl counts, not in code. The four options below are only a fallback, used when the script can't load those settings.
trackScreenViews- Fallback for Page views (default: true)trackOutgoingLinks- Fallback for Clicks on links to other sites (default: true)trackAttributes- Fallback for Clicks you marked in your code, elements withdata-track(default: true)trackHashChanges- Fallback for Address changes after #, for hash-based routers (default: false)sessionReplay- Technical options for the screen recorder. Most sites need none. Turning replay on and choosing how many visits to record is done in Settings → Site → What Pieowl counts. Text and form fields are always hidden. See session replay docs.blockSelector- CSS selector for elements to replace with a placeholder (default:[data-pieowl-replay-block])blockClass- Class name that blocks elements from being recordedignoreSelector- CSS selector for elements excluded from interaction trackingflushIntervalMs- How often (ms) recorded events are sent to the server (default: 10000)maxEventsPerChunk- Maximum events per payload chunk (default: 200)maxPayloadBytes- Maximum payload size in bytes (default: 1048576)scriptUrl- Custom URL for the replay script (script-tag builds only)
Step 3: Usage
import { pieowl } from './pieowl';
pieowl.track('my_event', { foo: 'bar' });Usage
The Web SDK has the same methods as the JavaScript SDK. It also adds:
screenView()to track a page view by hand- Session replay, turned on per site in Settings → Site. See Session replay.
allowReplay()to start session replay once the visitor agrees, when Record only after visitors agree is on. See Consent management.