mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-24 02:06:19 +01:00
collect pagetitle, update subdivision2 data type
This commit is contained in:
parent
55a586fe27
commit
6c302a7325
@ -25,7 +25,7 @@ CREATE TABLE `session` (
|
||||
`language` VARCHAR(35) NULL,
|
||||
`country` CHAR(2) NULL,
|
||||
`subdivision1` CHAR(3) NULL,
|
||||
`subdivision2` CHAR(3) NULL,
|
||||
`subdivision2` VARCHAR(50) NULL,
|
||||
`city` VARCHAR(50) NULL,
|
||||
`created_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
|
||||
|
@ -35,7 +35,7 @@ model Session {
|
||||
language String? @db.VarChar(35)
|
||||
country String? @db.Char(2)
|
||||
subdivision1 String? @db.Char(3)
|
||||
subdivision2 String? @db.Char(3)
|
||||
subdivision2 String? @db.VarChar(50)
|
||||
city String? @db.VarChar(50)
|
||||
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamp(0)
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "session" ADD COLUMN "city" VARCHAR(50),
|
||||
ADD COLUMN "subdivision1" CHAR(3),
|
||||
ADD COLUMN "subdivision2" CHAR(3);
|
||||
ADD COLUMN "subdivision2" VARCHAR(50);
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "website_event" ADD COLUMN "page_title" VARCHAR(500);
|
||||
|
@ -35,7 +35,7 @@ model Session {
|
||||
language String? @db.VarChar(35)
|
||||
country String? @db.Char(2)
|
||||
subdivision1 String? @db.Char(3)
|
||||
subdivision2 String? @db.Char(3)
|
||||
subdivision2 String? @db.VarChar(50)
|
||||
city String? @db.VarChar(50)
|
||||
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
|
||||
|
||||
|
@ -69,7 +69,7 @@ export async function getLocation(ip) {
|
||||
const result = lookup.get(ip);
|
||||
const country = result?.country?.iso_code ?? result?.registered_country?.iso_code;
|
||||
const subdivision1 = result?.subdivisions[0]?.iso_code;
|
||||
const subdivision2 = result?.subdivisions[1]?.iso_code;
|
||||
const subdivision2 = result?.subdivisions[1]?.names?.en;
|
||||
const city = result?.city?.names?.en;
|
||||
|
||||
return { country, subdivision1, subdivision2, city };
|
||||
|
3470
public/iso-3166-2.json
Normal file
3470
public/iso-3166-2.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -6,12 +6,12 @@ const maxmind = require('maxmind');
|
||||
|
||||
async function getLocation() {
|
||||
const lookup = await maxmind.open(path.resolve('../node_modules/.geo/GeoLite2-City.mmdb'));
|
||||
const result = lookup.get('104.93.28.0');
|
||||
const result = lookup.get('46.135.3.1');
|
||||
|
||||
const country = result?.country?.iso_code ?? result?.registered_country?.iso_code;
|
||||
const subdivision = result?.subdivisions[0].iso_code;
|
||||
const subdivision2 = result?.subdivisions[0].names;
|
||||
const subdivision3 = result?.subdivisions[1].names;
|
||||
const subdivision = result?.subdivisions[0]?.iso_code;
|
||||
const subdivision2 = result?.subdivisions[0]?.names?.en;
|
||||
const subdivision3 = result?.subdivisions[1]?.names?.en;
|
||||
const city = result?.city?.names?.en;
|
||||
console.log(result);
|
||||
console.log(country, subdivision, city, subdivision2, subdivision3);
|
||||
|
@ -47,6 +47,7 @@
|
||||
(dnt && doNotTrack()) ||
|
||||
(domain && !domains.includes(hostname));
|
||||
|
||||
const tracker_delay_duration = 300;
|
||||
const _data = 'data-';
|
||||
const _false = 'false';
|
||||
const attr = currentScript.getAttribute.bind(currentScript);
|
||||
@ -68,6 +69,7 @@
|
||||
let listeners = {};
|
||||
let currentUrl = `${pathname}${search}`;
|
||||
let currentRef = document.referrer;
|
||||
let currentPageTitle = document.title;
|
||||
let cache;
|
||||
|
||||
/* Collect metrics */
|
||||
@ -92,22 +94,35 @@
|
||||
.then(text => (cache = text));
|
||||
};
|
||||
|
||||
const trackView = (url = currentUrl, referrer = currentRef, websiteId = website) =>
|
||||
const trackView = (
|
||||
url = currentUrl,
|
||||
referrer = currentRef,
|
||||
websiteId = website,
|
||||
pageTitle = currentPageTitle,
|
||||
) =>
|
||||
collect(
|
||||
'pageview',
|
||||
assign(getPayload(), {
|
||||
website: websiteId,
|
||||
url,
|
||||
referrer,
|
||||
pageTitle,
|
||||
}),
|
||||
);
|
||||
|
||||
const trackEvent = (eventName, eventData, url = currentUrl, websiteId = website) =>
|
||||
const trackEvent = (
|
||||
eventName,
|
||||
eventData,
|
||||
url = currentUrl,
|
||||
websiteId = website,
|
||||
pageTitle = currentPageTitle,
|
||||
) =>
|
||||
collect(
|
||||
'event',
|
||||
assign(getPayload(), {
|
||||
website: websiteId,
|
||||
url,
|
||||
pageTitle,
|
||||
eventName: eventName,
|
||||
eventData: eventData,
|
||||
}),
|
||||
@ -162,6 +177,7 @@
|
||||
const handlePush = (state, title, url) => {
|
||||
if (!url) return;
|
||||
|
||||
observeTitle();
|
||||
currentRef = currentUrl;
|
||||
const newUrl = url.toString();
|
||||
|
||||
@ -172,7 +188,7 @@
|
||||
}
|
||||
|
||||
if (currentUrl !== currentRef) {
|
||||
trackView();
|
||||
setTimeout(() => trackView(), tracker_delay_duration);
|
||||
}
|
||||
};
|
||||
|
||||
@ -189,6 +205,19 @@
|
||||
observer.observe(document, { childList: true, subtree: true });
|
||||
};
|
||||
|
||||
const observeTitle = () => {
|
||||
const monitorMutate = mutations => {
|
||||
currentPageTitle = mutations[0].target.text;
|
||||
};
|
||||
|
||||
const observer = new MutationObserver(monitorMutate);
|
||||
observer.observe(document.querySelector('title'), {
|
||||
subtree: true,
|
||||
characterData: true,
|
||||
childList: true,
|
||||
});
|
||||
};
|
||||
|
||||
/* Global */
|
||||
|
||||
if (!window.umami) {
|
||||
|
Loading…
Reference in New Issue
Block a user