|
1 | 1 | import { EventQueue } from './queue.js'; |
2 | 2 | import { setCookie, getCookie, getAnalyticsCookie, generateId } from './cookie.js'; |
3 | 3 | import { sendEvent } from './http.js'; |
| 4 | +import { version } from '../package.json'; |
4 | 5 |
|
5 | 6 | // Define TinyTag class |
6 | 7 | function TinyTag() { |
@@ -42,11 +43,34 @@ TinyTag.prototype.parseQueryParams = function () { |
42 | 43 | }; |
43 | 44 |
|
44 | 45 | TinyTag.prototype.getDefaultContext = function () { |
| 46 | + const initialReferrer = document.referrer || null; // Initial referrer from page load |
| 47 | + const referrer = document.referrer || null; // Current referrer (same as initial for single-page) |
| 48 | + const hostname = window.location.hostname; |
| 49 | + |
45 | 50 | return { |
| 51 | + library: { |
| 52 | + name: 'TinyTag', |
| 53 | + version: version |
| 54 | + }, |
| 55 | + locale: navigator.language || navigator.userLanguage || '', |
| 56 | + page: { |
| 57 | + initial_referrer: initialReferrer, |
| 58 | + initial_referring_domain: initialReferrer ? new URL(initialReferrer).hostname : null, |
| 59 | + path: window.location.pathname, |
| 60 | + referrer: referrer, |
| 61 | + referring_domain: referrer ? new URL(referrer).hostname : null, |
| 62 | + search: window.location.search, |
| 63 | + tab_url: window.location.href, |
| 64 | + title: document.title, |
| 65 | + url: window.location.href |
| 66 | + }, |
46 | 67 | userAgent: navigator.userAgent, |
47 | 68 | screen: { |
48 | | - width: window.screen.width, |
49 | | - height: window.screen.height |
| 69 | + density: window.devicePixelRatio || 1, |
| 70 | + height: window.screen.height, |
| 71 | + innerHeight: window.innerHeight, |
| 72 | + innerWidth: window.innerWidth, |
| 73 | + width: window.screen.width |
50 | 74 | }, |
51 | 75 | timestamp: new Date().toISOString(), |
52 | 76 | page: { |
|
0 commit comments