Skip to content

Commit 8aef656

Browse files
committed
adding additional context
1 parent 8c5b63a commit 8aef656

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/index.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { EventQueue } from './queue.js';
22
import { setCookie, getCookie, getAnalyticsCookie, generateId } from './cookie.js';
33
import { sendEvent } from './http.js';
4+
import { version } from '../package.json';
45

56
// Define TinyTag class
67
function TinyTag() {
@@ -42,11 +43,34 @@ TinyTag.prototype.parseQueryParams = function () {
4243
};
4344

4445
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+
4550
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+
},
4667
userAgent: navigator.userAgent,
4768
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
5074
},
5175
timestamp: new Date().toISOString(),
5276
page: {

0 commit comments

Comments
 (0)