diff --git a/src/analytics/index.tsx b/src/analytics/index.tsx index cde37ab711..3d39f464cd 100644 --- a/src/analytics/index.tsx +++ b/src/analytics/index.tsx @@ -24,7 +24,7 @@ import { import {type Metrics, metrics} from '#/analytics/metrics' import * as refParams from '#/analytics/misc/refParams' import * as env from '#/env' -import {useGeolocation} from '#/geolocation' +import {useGeolocationServiceResponse} from '#/geolocation/service' import {device} from '#/storage' export * as utils from '#/analytics/utils' @@ -104,7 +104,7 @@ const Context = createContext({ referrerSrc: refParams.src, referrerUrl: refParams.url, }, - geolocation: device.get(['mergedGeolocation']) || { + geolocation: device.get(['geolocationServiceResponse']) || { countryCode: '', regionCode: '', }, @@ -137,7 +137,7 @@ export function AnalyticsContext({ } } const sessionId = useSessionId() - const geolocation = useGeolocation() + const geolocation = useGeolocationServiceResponse() const parentContext = useContext(Context) const childContext = useMemo(() => { const combinedMetadata = { diff --git a/src/analytics/utils.ts b/src/analytics/utils.ts index cd7766bd9f..5427bad0f8 100644 --- a/src/analytics/utils.ts +++ b/src/analytics/utils.ts @@ -7,6 +7,7 @@ import { type MergeableMetadata, type SessionMetadata, } from '#/analytics/metadata' +import {getIPGeolocationString} from '#/geolocation/util' /** * Thin `useMemo` wrapper that marks the metadata as memoized and provides a @@ -47,5 +48,6 @@ export function getAnalyticsHeaders() { return { 'X-Bsky-Device-Id': getDeviceId(), 'X-Bsky-Session-Id': getSessionId(), + 'X-Bsky-IP-Geolocation': getIPGeolocationString(), } } diff --git a/src/geolocation/util.ts b/src/geolocation/util.ts index 74311e7b90..44db7c30af 100644 --- a/src/geolocation/util.ts +++ b/src/geolocation/util.ts @@ -128,12 +128,17 @@ export function mergeGeolocations( } /** - * Get's the merged geolocation as a string in the format of + * Get's the IP-based geolocation as a string in the format of * "countryCode-regionCode", or just "countryCode" if regionCode is not * available. + * + * IMPORTANT: this method should only return IP-based data, not the user's GPS + * based data. IP-based data we can already infer from requests, but for + * consistency between frontend and backend, we sometimes want to share the + * value we have on the frontend with the backend. */ -export function getGeolocationString() { - const geo = device.get(['mergedGeolocation']) +export function getIPGeolocationString() { + const geo = device.get(['geolocationServiceResponse']) if (!geo) return const {countryCode, regionCode} = geo if (countryCode) {