📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Rename to replaylibrary
Blue Mouse8d5fbb6df0f0
diff --git a/packages/tracker-js/rollup.config.mjs b/packages/tracker-js/rollup.config.mjsindex b0f37730b..f19f5cc6d 100644--- a/packages/tracker-js/rollup.config.mjs+++ b/packages/tracker-js/rollup.config.mjs@@ -8,7 +8,7 @@ import { createRequire } from 'node:module'import { dirname, join } from 'node:path'const require = createRequire(import.meta.url)-const rrwebDistFile = 'rrweb.min.js'+const rrwebDistFile = 'replaylibrary.min.js'const rrwebPackageFile = 'rrweb.umd.min.cjs'const rrwebDistPath = join(dirname(require.resolve('rrweb')), rrwebPackageFile)diff --git a/packages/tracker-js/src/Lib.ts b/packages/tracker-js/src/Lib.tsindex 32f543de2..88b47f88e 100644--- a/packages/tracker-js/src/Lib.ts+++ b/packages/tracker-js/src/Lib.ts@@ -281,8 +281,8 @@ export const defaultSessionReplayActions: SessionReplayActions = {const DEFAULT_API_HOST = 'https://api.swetrix.com/log'const DEFAULT_API_BASE = 'https://api.swetrix.com'-const DEFAULT_RRWEB_FILE = 'rrweb.min.js'-const DEFAULT_RRWEB_URL = `https://swetrix.org/${DEFAULT_RRWEB_FILE}`+const DEFAULT_RRWEB_FILE = 'replaylibrary.min.js'+const DEFAULT_RRWEB_URL = `https://cdn.jsdelivr.net/npm/swetrix@latest/dist/${DEFAULT_RRWEB_FILE}`const DEFAULT_SESSION_REPLAY_FLUSH_INTERVAL = 5000const DEFAULT_SESSION_REPLAY_MAX_EVENTS = 100const DEFAULT_SESSION_REPLAY_PRIVACY: SessionReplayPrivacy = 'total'@@ -1102,6 +1102,14 @@ export class Lib {})if (trackerScript?.src) {+ const { hostname, pathname } = new URL(trackerScript.src)+ if (+ hostname === 'swetrix.org' &&+ /^\/swetrix(\.min)?\.js$/i.test(pathname)+ ) {+ return DEFAULT_RRWEB_URL+ }+return new URL(DEFAULT_RRWEB_FILE, trackerScript.src).toString()}diff --git a/packages/tracker-js/tests/sessionReplay.test.ts b/packages/tracker-js/tests/sessionReplay.test.tsindex e01f54a72..4ba426d6d 100644--- a/packages/tracker-js/tests/sessionReplay.test.ts+++ b/packages/tracker-js/tests/sessionReplay.test.ts@@ -4,9 +4,7 @@ import { Lib } from '../src/Lib'import { setLocation } from './testUtils'const PROJECT_ID = 'test-project-id'-const RRWEB_URL = 'https://swetrix.org/rrweb.min.js'-const SIBLING_RRWEB_URL = 'https://cdn.swetrix.test/assets/rrweb.min.js'-const LOCAL_RRWEB_URL = 'http://localhost:8080/dist/rrweb.min.js'+const RRWEB_URL = 'https://cdn.jsdelivr.net/npm/swetrix@latest/dist/replaylibrary.min.js'const loadTracker = async () => {jest.resetModules()@@ -76,9 +74,9 @@ describe('Session replay tracking', () => {expect(fetchMock).not.toHaveBeenCalled()})- test('session replay script defaults to the loaded tracker script directory', async () => {+ test('session replay script uses jsDelivr for the public swetrix.org loader', async () => {const script = document.createElement('script')- script.src = 'https://cdn.swetrix.test/assets/swetrix.js'+ script.src = 'https://swetrix.org/swetrix.js'document.head.appendChild(script)const { init } = await loadTracker()@@ -86,22 +84,7 @@ describe('Session replay tracking', () => {expect(document.querySelector<HTMLScriptElement>(- `script[src="${SIBLING_RRWEB_URL}"]`,- ),- ).toBeTruthy()- })-- test('session replay script resolves beside a localhost tracker build', async () => {- const script = document.createElement('script')- script.src = 'http://localhost:8080/dist/swetrix.js'- document.head.appendChild(script)-- const { init } = await loadTracker()- init(PROJECT_ID, { devMode: true, sessionReplay: true })-- expect(- document.querySelector<HTMLScriptElement>(- `script[src="${LOCAL_RRWEB_URL}"]`,+ `script[src="${RRWEB_URL}"]`,),).toBeTruthy()})