diff --git a/CHANGELOG.md b/CHANGELOG.md index 4752ea1..f4406de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 2.7.0 +* added regional statistics +* removed DNT * updated dependencies ## 2.6.0 diff --git a/src/client.ts b/src/client.ts index 76905d4..1dfb969 100644 --- a/src/client.ts +++ b/src/client.ts @@ -63,7 +63,6 @@ export class PirschNodeApiClient extends PirschCoreClient { const element: PirschHit = { url: url.toString(), ip: request.socket.remoteAddress ?? "", - dnt: this.getHeader(request.headers, "dnt"), user_agent: this.getHeader(request.headers, "user-agent") ?? "", accept_language: this.getHeader(request.headers, "accept-language"), sec_ch_ua: this.getHeader(request.headers, "Sec-CH-UA"), diff --git a/src/constants.ts b/src/constants.ts index 30a98e7..fb7c191 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -51,6 +51,7 @@ export enum PirschEndpoint { BROWSER = "statistics/browser", BROWSER_VERSION = "statistics/browser/version", COUNTRY = "statistics/country", + REGION = "statistics/region", CITY = "statistics/city", PLATFORM = "statistics/platform", SCREEN = "statistics/screen", diff --git a/src/core.ts b/src/core.ts index ad11f17..e018aa9 100644 --- a/src/core.ts +++ b/src/core.ts @@ -42,6 +42,7 @@ import { PirschBatchSession, PirschBatchEvent, TagStats, + PirschRegionStats, } from "./types"; import { PIRSCH_DEFAULT_BASE_URL, PIRSCH_DEFAULT_TIMEOUT, PirschEndpoint } from "./constants"; @@ -112,10 +113,6 @@ export abstract class PirschCoreClient extends PirschCommon { * @returns APIError or an empty promise, in case something went wrong */ async hit(hit: PirschHit): Promise> { - if (hit.dnt === "1") { - return; - } - return await this.performPost(PirschEndpoint.HIT, hit); } @@ -126,13 +123,7 @@ export abstract class PirschCoreClient extends PirschCommon { * @returns APIError or an empty promise, in case something went wrong */ async batchHits(hits: PirschBatchHit[]): Promise> { - const filtered = hits.filter(hit => hit.dnt !== "1"); - - if (filtered.length === 0) { - return; - } - - return await this.performPost(PirschEndpoint.HIT_BATCH, filtered); + return await this.performPost(PirschEndpoint.HIT_BATCH, hits); } /** @@ -151,10 +142,6 @@ export abstract class PirschCoreClient extends PirschCommon { duration = 0, meta?: Record ): Promise> { - if (hit.dnt === "1") { - return; - } - const event: PirschEvent = { event_name: name, event_duration: duration, @@ -180,13 +167,7 @@ export abstract class PirschCoreClient extends PirschCommon { meta?: Record; }[] ): Promise> { - const filtered = events.filter(event => event.hit.dnt !== "1"); - - if (filtered.length === 0) { - return; - } - - const results = filtered.map(({ name, hit, time, duration = 0, meta }) => { + const results = events.map(({ name, hit, time, duration = 0, meta }) => { const event: PirschBatchEvent = { event_name: name, event_duration: duration, @@ -208,10 +189,6 @@ export abstract class PirschCoreClient extends PirschCommon { * @returns APIError or an empty promise, in case something went wrong */ async session(session: PirschSession): Promise> { - if (session.dnt === "1") { - return; - } - return await this.performPost(PirschEndpoint.SESSION, session); } @@ -222,13 +199,7 @@ export abstract class PirschCoreClient extends PirschCommon { * @returns APIError or an empty promise, in case something went wrong */ async batchSessions(sessions: PirschBatchSession[]): Promise> { - const filtered = sessions.filter(session => session.dnt !== "1"); - - if (filtered.length === 0) { - return; - } - - return await this.performPost(PirschEndpoint.SESSION_BATCH, filtered); + return await this.performPost(PirschEndpoint.SESSION_BATCH, sessions); } /** @@ -551,6 +522,17 @@ export abstract class PirschCoreClient extends PirschCommon { return await this.performFilteredGet(PirschEndpoint.COUNTRY, filter); } + /** + * region returns regional statistics. + * + * @param filter used to filter the result set. + */ + async region(filter: PirschFilter): Promise { + this.accessModeCheck("region"); + + return await this.performFilteredGet(PirschEndpoint.REGION, filter); + } + /** * city returns city statistics. * @@ -693,6 +675,7 @@ export abstract class PirschCoreClient extends PirschCommon { event_meta_key: filter.event_meta_key, language: filter.language, country: filter.country, + region: filter.region, city: filter.city, referrer: filter.referrer, referrer_name: filter.referrer_name, diff --git a/src/types.ts b/src/types.ts index 22faf2f..24bf5e4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -95,7 +95,6 @@ export interface PirschAuthenticationResponse { export interface PirschHit { url: string; ip: string; - dnt?: string; user_agent: string; accept_language?: string; sec_ch_ua?: string; @@ -145,7 +144,7 @@ export interface PirschBatchEvent extends PirschEvent { * all other fields can be left empty, but it's highly recommended to send all fields to generate reliable data. * The fields can be set from the request headers. */ -export type PirschSession = Pick; +export type PirschSession = Pick; /** * PirschBatchSession contains all required fields to send batched sessions to Pirsch. The IP and User-Agent are mandatory, @@ -164,7 +163,6 @@ export interface PirschBatchSession extends PirschSession { export interface PirschBrowserHit { url: string; title?: string; - dnt?: string; accept_language?: string; referrer?: string; screen_width?: number; @@ -220,6 +218,7 @@ export interface PirschFilter { event_meta?: Record; language?: string; country?: string; + region?: string; city?: string; referrer?: string; referrer_name?: string; @@ -523,10 +522,20 @@ export interface PirschCountryStats extends PirschMetaStats { country_code: string; } +/* + * PirschRegionStats is the result type for regional statistics. + */ +export interface PirschRegionStats extends PirschMetaStats { + country_code: string; + region: string; +} + /* * PirschCityStats is the result type for city statistics. */ export interface PirschCityStats extends PirschMetaStats { + country_code: string; + region: string; city: string; } diff --git a/src/web.ts b/src/web.ts index 6b5a2f8..c74123f 100644 --- a/src/web.ts +++ b/src/web.ts @@ -70,11 +70,6 @@ export class PirschWebClient extends PirschCommon { public async hit(hit?: Partial): Promise { const data = { ...this.hitFromBrowser(), ...hit }; const parameters = this.browserHitToGetParameters(data); - - if (data.dnt === "1") { - return; - } - await this.get(PirschEndpoint.HIT, { parameters }); } @@ -93,11 +88,6 @@ export class PirschWebClient extends PirschCommon { hit?: Partial ): Promise { const data = { ...this.hitFromBrowser(), ...hit }; - - if (data.dnt === "1") { - return; - } - await this.post( PirschEndpoint.EVENT, { @@ -118,11 +108,6 @@ export class PirschWebClient extends PirschCommon { */ public async customHit(hit: PirschBrowserHit): Promise { const parameters = this.browserHitToGetParameters(hit); - - if (hit.dnt === "1") { - return; - } - await this.get(PirschEndpoint.HIT, { parameters }); } @@ -140,10 +125,6 @@ export class PirschWebClient extends PirschCommon { hit: PirschBrowserHit, meta?: Record ): Promise { - if (hit.dnt === "1") { - return; - } - await this.post( PirschEndpoint.EVENT, { @@ -165,19 +146,13 @@ export class PirschWebClient extends PirschCommon { * @returns Hit object containing all necessary fields. */ public hitFromBrowser(): PirschBrowserHit { - const element: PirschBrowserHit = { + return { url: this.generateUrl(), title: document.title, referrer: document.referrer, screen_width: screen.width, screen_height: screen.height, }; - - if (navigator.doNotTrack === "1") { - element.dnt = navigator.doNotTrack; - } - - return element; } private browserHitToGetParameters(data: PirschBrowserHit) {