Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ If you need multiple instances just duplicate the snippet with a different insta
The Woopra tracker can be customized using the config function. Find below the list of options:

| Option | Default | Description |
|----------------------------------|----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------|
| -------------------------------- | -------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| **domain** | N/A: required | **REQUIRED** Project Name in Woopra. Must be explicitly set for tracker to work. |
| beacons | Browser support | Whether to use `navigator.sendBeacon` instead of `<script>` injection to send actions to Woopra's tracking servers |
| click_pause | `250` | Time in millisecond to pause the browser to ensure that the event is tracked when visitor clicks on an element url. |
Expand All @@ -58,6 +58,7 @@ The Woopra tracker can be customized using the config function. Find below the l
| ping | `false` | Ping woopra servers to ensure that the visitor is still on the webpage. |
| ping_interval | `12000` | Time interval in milliseconds between each ping. (min: `6000`, max: `60000`) |
| protocol | `https://` | The protocol used to contact Woopra's servers. `http://` forces unsecure mode and `//` follows the page's protocol |
| tracking_domain | N/A | Custom tracking domain. When set, all tracking requests are sent to `https://{tracking_domain}/track/` |

The `config()` function supports key/value singleton argument:

Expand Down Expand Up @@ -150,7 +151,7 @@ When you track custom events, remember to update your schema on Woopra. That wil
Below is another example to track when people click on the play button with id="play-button":

```javascript
document.getElementById('play-button').onclick = function() {
document.getElementById('play-button').onclick = function () {
woopra.track('play', {
artist: 'Dave Brubeck',
song: 'Take Five',
Expand Down
4 changes: 2 additions & 2 deletions dist/w.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/w.js.map

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions dist/wpt.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Copyright (c) 2025 Woopra, Inc.
* Copyright (c) 2026 Woopra, Inc.
*
* For license information please see https://static.woopra.com/js/w.js.LICENSE.txt
*/
Expand Down Expand Up @@ -716,6 +716,7 @@
var KEY_REGION = 'region';
var KEY_SAVE_URL_HASH = 'save_url_hash';
var KEY_THIRD_PARTY = 'third_party';
var KEY_TRACKING_DOMAIN = 'tracking_domain';
var KEY_USE_COOKIES = 'use_cookies';
var META_CANCELLED = 'cancelled';
var META_DIRTY = 'dirty';
Expand Down Expand Up @@ -2584,17 +2585,24 @@
}

var protocol = this.getProtocol();
var trackingDomain = this.config(KEY_TRACKING_DOMAIN);

if (path && !Woopra.endsWith(path, '/')) {
path += '/';
} // Use custom tracking domain if configured


if (trackingDomain) {
return protocol + "//" + trackingDomain + "/track/" + path;
} // Fall back to region-based endpoints


if (this.config(KEY_THIRD_PARTY) && !this.config(KEY_DOMAIN)) {
throw new Error('Error: `domain` is not set.');
}

var thirdPartyPath = this.config(KEY_THIRD_PARTY) ? "tp/" + this.config(KEY_DOMAIN) : '';

if (path && !Woopra.endsWith(path, '/')) {
path += '/';
}

if (thirdPartyPath && !Woopra.startsWith(path, '/')) {
thirdPartyPath += '/';
}
Expand Down
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export const KEY_PROTOCOL = 'protocol';
export const KEY_REGION = 'region';
export const KEY_SAVE_URL_HASH = 'save_url_hash';
export const KEY_THIRD_PARTY = 'third_party';
export const KEY_TRACKING_DOMAIN = 'tracking_domain';
export const KEY_USE_COOKIES = 'use_cookies';

export const META_CANCELLED = 'cancelled';
Expand Down
16 changes: 12 additions & 4 deletions src/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
KEY_REGION,
KEY_SAVE_URL_HASH,
KEY_THIRD_PARTY,
KEY_TRACKING_DOMAIN,
KEY_USE_COOKIES,
LIFECYCLE_ACTION,
LIFECYCLE_PAGE,
Expand Down Expand Up @@ -321,7 +322,18 @@ export default class Tracker {
*/
getEndpoint(path = '') {
const protocol = this.getProtocol();
const trackingDomain = this.config(KEY_TRACKING_DOMAIN);

if (path && !Woopra.endsWith(path, '/')) {
path += '/';
}

// Use custom tracking domain if configured
if (trackingDomain) {
return `${protocol}//${trackingDomain}/track/${path}`;
}

// Fall back to region-based endpoints
if (this.config(KEY_THIRD_PARTY) && !this.config(KEY_DOMAIN)) {
throw new Error('Error: `domain` is not set.');
}
Expand All @@ -330,10 +342,6 @@ export default class Tracker {
? `tp/${this.config(KEY_DOMAIN)}`
: '';

if (path && !Woopra.endsWith(path, '/')) {
path += '/';
}

if (thirdPartyPath && !Woopra.startsWith(path, '/')) {
thirdPartyPath += '/';
}
Expand Down
28 changes: 28 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,34 @@ describe('Woopra Tracker', function () {
it('test `getEndpoint` when configured using EU region', function () {
expect(tracker.getEndpoint()).to.equal('https://www.woopra.com/track/');
});

it('test `getEndpoint` when configured with custom tracking_domain', function () {
tracker.config('tracking_domain', 'custom.example.com');

expect(tracker.getEndpoint()).to.equal(
'https://custom.example.com/track/'
);
});

it('test `getEndpoint` with custom tracking_domain and a path', function () {
tracker.config('tracking_domain', 'custom.example.com');

expect(tracker.getEndpoint('ce')).to.equal(
'https://custom.example.com/track/ce/'
);
expect(tracker.getEndpoint('push/')).to.equal(
'https://custom.example.com/track/push/'
);
});

it('test `getEndpoint` custom tracking_domain takes priority over region', function () {
tracker.config('region', 'kr');
tracker.config('tracking_domain', 'custom.example.com');

expect(tracker.getEndpoint()).to.equal(
'https://custom.example.com/track/'
);
});
});

describe('Outgoing Link Helpers', function () {
Expand Down