mirror of
https://github.com/pupperpowell/bibdle.git
synced 2026-10-22 05:54:10 -04:00
first pass analytics redo
This commit is contained in:
1 parent
b656fd04c0
commit
45ffa39f2a
69 files changed
+6400
-1138
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import { describe, test, expect } from 'bun:test';
|
||||
import { parseAcquisition } from '$lib/utils/acquisition';
|
||||
|
||||
describe('parseAcquisition', () => {
|
||||
test('extracts utm parameters and ref', () => {
|
||||
const a = parseAcquisition('?utm_source=bluesky&utm_medium=social&utm_campaign=launch', '');
|
||||
expect(a.utm_source).toBe('bluesky');
|
||||
expect(a.utm_medium).toBe('social');
|
||||
expect(a.utm_campaign).toBe('launch');
|
||||
});
|
||||
|
||||
test('falls back to ref for the source', () => {
|
||||
expect(parseAcquisition('?ref=hn', '').utm_source).toBe('hn');
|
||||
});
|
||||
|
||||
test('keeps an external referrer', () => {
|
||||
const a = parseAcquisition('', 'https://news.ycombinator.com/item?id=1');
|
||||
expect(a.referrer).toBe('https://news.ycombinator.com/item?id=1');
|
||||
});
|
||||
|
||||
test('blank and whitespace values become null', () => {
|
||||
const a = parseAcquisition('?utm_source=%20%20', '');
|
||||
expect(a.utm_source).toBeNull();
|
||||
expect(a.referrer).toBeNull();
|
||||
});
|
||||
|
||||
test('caps absurdly long values', () => {
|
||||
const a = parseAcquisition(`?utm_source=${'x'.repeat(500)}`, '');
|
||||
expect(a.utm_source!.length).toBe(256);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user