diff --git a/frontend/src/lib/components/IframedToolbarBrowser/iframedToolbarBrowserLogic.ts b/frontend/src/lib/components/IframedToolbarBrowser/iframedToolbarBrowserLogic.ts index 71d1f657b1f5fa..9aafee105cd767 100644 --- a/frontend/src/lib/components/IframedToolbarBrowser/iframedToolbarBrowserLogic.ts +++ b/frontend/src/lib/components/IframedToolbarBrowser/iframedToolbarBrowserLogic.ts @@ -140,6 +140,12 @@ export const iframedToolbarBrowserLogic = kea([ return iframeWidth ? calculateViewportRange(heatmapFilters, iframeWidth) : { min: 0, max: 1800 } }, ], + currentFullUrl: [ + (s) => [s.browserUrl, s.currentPath], + (browserUrl, currentPath) => { + return browserUrl + '/' + currentPath + }, + ], }), listeners(({ actions, cache, props, values }) => ({ diff --git a/frontend/src/scenes/dashboard/Dashboards.stories.tsx b/frontend/src/scenes/dashboard/Dashboards.stories.tsx index 1e25ad376ba95d..34e6be5f20878d 100644 --- a/frontend/src/scenes/dashboard/Dashboards.stories.tsx +++ b/frontend/src/scenes/dashboard/Dashboards.stories.tsx @@ -9,7 +9,7 @@ import { urls } from 'scenes/urls' import { mswDecorator } from '~/mocks/browser' import { useAvailableFeatures } from '~/mocks/features' -import { DashboardMode } from '~/types' +import { BaseMathType, DashboardMode, EntityTypes } from '~/types' import { dashboardTemplatesLogic } from './dashboards/templates/dashboardTemplatesLogic' @@ -76,8 +76,8 @@ export const NewSelectVariables = (): JSX.Element => { type: 'event', default: { id: '$pageview', - math: 'dau', - type: 'events', + math: BaseMathType.UniqueUsers, + type: EntityTypes.EVENTS, }, required: true, description: 'Add the current_url filter that matches your sign up page', @@ -88,8 +88,8 @@ export const NewSelectVariables = (): JSX.Element => { type: 'event', default: { id: '$pageview', - math: 'dau', - type: 'events', + math: BaseMathType.UniqueUsers, + type: EntityTypes.EVENTS, }, required: true, description: @@ -101,8 +101,8 @@ export const NewSelectVariables = (): JSX.Element => { type: 'event', default: { id: '$pageview', - math: 'dau', - type: 'events', + math: BaseMathType.UniqueUsers, + type: EntityTypes.EVENTS, }, required: false, description: 'Select the event which best represents when a user is activated', diff --git a/frontend/src/scenes/dashboard/dashboardTemplateVariablesLogic.ts b/frontend/src/scenes/dashboard/dashboardTemplateVariablesLogic.ts index e12513e025d384..340b6b2ed278e1 100644 --- a/frontend/src/scenes/dashboard/dashboardTemplateVariablesLogic.ts +++ b/frontend/src/scenes/dashboard/dashboardTemplateVariablesLogic.ts @@ -22,8 +22,8 @@ export interface DashboardTemplateVariablesLogicProps { const FALLBACK_EVENT = { id: '$pageview', - math: 'dau', - type: 'events', + math: BaseMathType.UniqueUsers, + type: EntityTypes.EVENTS, } export const dashboardTemplateVariablesLogic = kea([ @@ -39,6 +39,7 @@ export const dashboardTemplateVariablesLogic = kea ({ variableName, action }), + setVariableForPageview: (variableName: string, url: string) => ({ variableName, url }), setActiveVariableIndex: (index: number) => ({ index }), incrementActiveVariableIndex: true, possiblyIncrementActiveVariableIndex: true, @@ -162,6 +163,28 @@ export const dashboardTemplateVariablesLogic = kea { + const step: TemplateVariableStep = { + id: '$pageview', + math: BaseMathType.UniqueUsers, + type: EntityTypes.EVENTS, + order: 0, + name: '$pageview', + properties: [ + { + key: '$current_url', + value: url, + operator: 'icontains', + type: 'event', + }, + ], + } + const filterGroup: FilterType = { + events: [step], + } + actions.setVariable(variableName, filterGroup) + actions.setIsCurrentlySelectingElement(false) + }, toolbarMessageReceived: ({ type, payload }) => { if (type === PostHogAppToolbarEvent.PH_NEW_ACTION_CREATED) { actions.setVariableFromAction(payload.action.name, payload.action as ActionType) diff --git a/frontend/src/scenes/dashboard/newDashboardLogic.ts b/frontend/src/scenes/dashboard/newDashboardLogic.ts index 7e03ff6170fe14..fb83b3ca15b708 100644 --- a/frontend/src/scenes/dashboard/newDashboardLogic.ts +++ b/frontend/src/scenes/dashboard/newDashboardLogic.ts @@ -41,7 +41,7 @@ export function applyTemplate(obj: DashboardTile | JsonType, variables: Dashboar const variableId = obj.substring(1, obj.length - 1) const variable = variables.find((variable) => variable.id === variableId) if (variable && variable.default) { - return variable.default + return variable.default as JsonType } return obj } diff --git a/frontend/src/scenes/onboarding/productAnalyticsSteps/DashboardTemplateConfigureStep.tsx b/frontend/src/scenes/onboarding/productAnalyticsSteps/DashboardTemplateConfigureStep.tsx index cc432139aad056..ebda07635fcbbf 100644 --- a/frontend/src/scenes/onboarding/productAnalyticsSteps/DashboardTemplateConfigureStep.tsx +++ b/frontend/src/scenes/onboarding/productAnalyticsSteps/DashboardTemplateConfigureStep.tsx @@ -18,12 +18,18 @@ const UrlInput = ({ iframeRef }: { iframeRef: React.RefObject const { setBrowserUrl, setCurrentPath } = useActions( iframedToolbarBrowserLogic({ iframeRef, clearBrowserUrlOnUnmount: true }) ) - const { browserUrl, currentPath } = useValues( + const { browserUrl, currentPath, currentFullUrl } = useValues( iframedToolbarBrowserLogic({ iframeRef, clearBrowserUrlOnUnmount: true }) ) const { snippetHosts } = useValues(sdksLogic) const { addUrl } = useActions(authorizedUrlListLogic({ actionId: null, type: AuthorizedUrlListType.TOOLBAR_URLS })) const [inputValue, setInputValue] = useState(currentPath) + const { activeDashboardTemplate } = useValues(newDashboardLogic) + const theDashboardTemplateVariablesLogic = dashboardTemplateVariablesLogic({ + variables: activeDashboardTemplate?.variables || [], + }) + const { setVariableForPageview } = useActions(theDashboardTemplateVariablesLogic) + const { activeVariable } = useValues(theDashboardTemplateVariablesLogic) useEffect(() => { setInputValue(currentPath) @@ -70,7 +76,12 @@ const UrlInput = ({ iframeRef }: { iframeRef: React.RefObject setCurrentPath(inputValue || '', true) }} /> - + setVariableForPageview(activeVariable.name, currentFullUrl)} + > Select pageview diff --git a/frontend/src/scenes/onboarding/productAnalyticsSteps/DashboardTemplateVariables.tsx b/frontend/src/scenes/onboarding/productAnalyticsSteps/DashboardTemplateVariables.tsx index 9f87ff0aeb0f4c..a6fe3e4cf6e9b4 100644 --- a/frontend/src/scenes/onboarding/productAnalyticsSteps/DashboardTemplateVariables.tsx +++ b/frontend/src/scenes/onboarding/productAnalyticsSteps/DashboardTemplateVariables.tsx @@ -6,7 +6,7 @@ import { useEffect, useState } from 'react' import { dashboardTemplateVariablesLogic } from 'scenes/dashboard/dashboardTemplateVariablesLogic' import { newDashboardLogic } from 'scenes/dashboard/newDashboardLogic' -import { DashboardTemplateVariableType } from '~/types' +import { DashboardTemplateVariableType, EntityTypes } from '~/types' function VariableSelector({ variableName, @@ -64,16 +64,26 @@ function VariableSelector({ Selected

-

- CSS selector:{' '} - {variable.default.selector || 'not set'} -

-

- Element href: {variable.default.href || 'not set'} -

-

- Page URL: {variable.default.url || 'any url'} -

+ {variable.default.type === EntityTypes.ACTIONS ? ( + <> +

+ CSS selector:{' '} + {variable.default.selector || 'not set'} +

+

+ Element href:{' '} + {variable.default.href || 'not set'} +

+

+ Page URL: {variable.default.url || 'any url'} +

+ + ) : variable.default.type === EntityTypes.EVENTS ? ( +

+ Pageview URL:{' '} + {variable.default.properties?.[0].value || 'any url'} +

+ ) : null}
diff --git a/frontend/src/toolbar/bar/toolbarLogic.ts b/frontend/src/toolbar/bar/toolbarLogic.ts index 8546f2448cd39a..8e279f2a971d62 100644 --- a/frontend/src/toolbar/bar/toolbarLogic.ts +++ b/frontend/src/toolbar/bar/toolbarLogic.ts @@ -490,7 +490,9 @@ export const toolbarLogic = kea([ actions.setAutomaticActionCreationEnabled(true, e.data.payload.name) return case PostHogAppToolbarEvent.PH_NAVIGATE: - window.location.href = e.data.payload.url + if (window.location.href !== e.data.payload.url) { + window.location.href = e.data.payload.url + } return default: console.warn(`[PostHog Toolbar] Received unknown parent window message: ${type}`) diff --git a/frontend/src/types.ts b/frontend/src/types.ts index a6db8171f301e7..7c2bff2d7cb619 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -1803,7 +1803,7 @@ export interface DashboardTemplateVariableType { name: string description: string type: 'event' - default: Record + default: TemplateVariableStep required: boolean touched?: boolean selector?: string @@ -2141,14 +2141,16 @@ export interface FilterType { } export interface TemplateVariableStep { - id: string - math: BaseMathType - name: string | null - order: number - type: EntityTypes + id?: string + math?: BaseMathType + name?: string | null + order?: number + type?: EntityTypes + event?: string selector?: string | null href?: string | null url?: string | null + properties?: Record[] } export interface PropertiesTimelineFilterType {