-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(web-analytics): Add guess for initial host filter #18818
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import api from 'lib/api' | |
import { RETENTION_FIRST_TIME, STALE_EVENT_SECONDS } from 'lib/constants' | ||
import { dayjs } from 'lib/dayjs' | ||
import { isNotNil } from 'lib/utils' | ||
import * as tldts from 'tldts' | ||
|
||
import { | ||
NodeKind, | ||
|
@@ -128,10 +129,16 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([ | |
}), | ||
reducers({ | ||
webAnalyticsFilters: [ | ||
initialWebAnalyticsFilter, | ||
null as WebAnalyticsPropertyFilters | null, | ||
{ | ||
loadInitialFiltersSuccess: (_, { initialFilters }) => { | ||
return initialFilters | ||
}, | ||
setWebAnalyticsFilters: (_, { webAnalyticsFilters }) => webAnalyticsFilters, | ||
togglePropertyFilter: (oldPropertyFilters, { key, value, type }): WebAnalyticsPropertyFilters => { | ||
if (!oldPropertyFilters) { | ||
oldPropertyFilters = [] | ||
} | ||
const similarFilterExists = oldPropertyFilters.some( | ||
(f) => f.type === type && f.key === key && f.operator === PropertyOperator.Exact | ||
) | ||
|
@@ -244,7 +251,11 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([ | |
dateTo, | ||
isGreaterThanMd: boolean, | ||
shouldShowGeographyTile | ||
): WebDashboardTile[] => { | ||
): WebDashboardTile[] | null => { | ||
if (!webAnalyticsFilters) { | ||
return null | ||
} | ||
|
||
const dateRange = { | ||
date_from: dateFrom, | ||
date_to: dateTo, | ||
|
@@ -734,12 +745,54 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([ | |
return !!geoIpPluginConfig && geoIpPluginConfig.enabled | ||
}, | ||
}, | ||
initialFilters: { | ||
_default: null as boolean | null, | ||
loadInitialFilters: async (): Promise<WebAnalyticsPropertyFilters> => { | ||
// This code guesses which is the marketing domain based on whether it's www or apex. We use this to set | ||
// the $host filter's initial state. Later on we'll have this as config that people can set, but for now | ||
// we try to do the smart thing without people needing to do anything | ||
const params = new URLSearchParams([ | ||
['key', '$host'], | ||
['event_name', '$pageview'], | ||
['event_name', '$pageleave'], | ||
['event_name', '$autocapture'], | ||
]) | ||
let propertiesResponse: unknown | ||
try { | ||
propertiesResponse = await api.get(`api/event/values/?${params}`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor remark: we do have some kind of API composition system under |
||
} catch { | ||
// ignore | ||
} | ||
if (!propertiesResponse || !Array.isArray(propertiesResponse) || propertiesResponse.length <= 1) { | ||
return [] | ||
} | ||
const hosts: string[] = propertiesResponse.map((x) => x.name) | ||
// at this point we have multiple hosts, pick the ones that are www or apex | ||
const wwwOrApex = hosts.filter((host) => { | ||
const subdomain = tldts.getSubdomain(host) | ||
return subdomain === '' || subdomain === 'www' | ||
}) | ||
Comment on lines
+771
to
+774
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps these subdomains on their own hold value? Suggestion that's non blocking: rename this to a |
||
if (wwwOrApex.length > 0 && wwwOrApex.length !== hosts.length) { | ||
return [ | ||
{ | ||
type: PropertyFilterType.Event, | ||
key: '$host', | ||
value: wwwOrApex, | ||
operator: PropertyOperator.Exact, | ||
}, | ||
] | ||
} else { | ||
return [] | ||
} | ||
}, | ||
}, | ||
})), | ||
|
||
// start the loaders after mounting the logic | ||
afterMount(({ actions }) => { | ||
actions.loadStatusCheck() | ||
actions.loadShouldShowGeographyTile() | ||
actions.loadInitialFilters() | ||
}), | ||
windowValues({ | ||
isGreaterThanMd: (window: Window) => window.innerWidth > 768, | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This potentially adds about 100KB of JS. Might be worth double checking if so... and perhaps just importing
{ getSubdomain }
solves this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect that this doesn't help much, as it'll still need the big list of 3LDs etc. Will try it anyway!