diff --git a/apps/web/src/components/element/form/TeeForm.vue b/apps/web/src/components/element/form/TeeForm.vue index 1d96d4ff5..970581c0d 100644 --- a/apps/web/src/components/element/form/TeeForm.vue +++ b/apps/web/src/components/element/form/TeeForm.vue @@ -151,9 +151,10 @@ const saveForm = async () => { isLoading.value = true const opportunity = new OpportunityApi(localForm.value, props.dataId, props.dataSlug || props.dataId, props.formType) requestResponse.value = await opportunity.fetch() - // analytics / send event - Analytics.sendEvent(TrackId.Results, getEventName()) + if (requestResponse.value.id) { + Analytics.sendEvent(TrackId.Results, getEventName(), { opportunityId: requestResponse.value.id }) + } } finally { isLoading.value = false formIsSent.value = true diff --git a/apps/web/src/service/api/opportunityApi.ts b/apps/web/src/service/api/opportunityApi.ts index d9d790d27..029ed7b09 100644 --- a/apps/web/src/service/api/opportunityApi.ts +++ b/apps/web/src/service/api/opportunityApi.ts @@ -43,6 +43,7 @@ export default class OpportunityApi extends RequestApi { async fetch() { let resp: ReqResp = {} try { + const payload: OpportunityBody = this.payload() const response = await fetch(this.url, { method: 'POST', headers: this._headers, @@ -53,6 +54,9 @@ export default class OpportunityApi extends RequestApi { resp.status = response.status resp.statusText = response.statusText resp.url = response.url + if (payload.opportunity.id) { + resp.id = payload.opportunity.id + } } catch (error: unknown) { resp.ok = false resp.status = 500 diff --git a/apps/web/src/types/otherTypes.ts b/apps/web/src/types/otherTypes.ts index 686f0a342..b906b3f52 100644 --- a/apps/web/src/types/otherTypes.ts +++ b/apps/web/src/types/otherTypes.ts @@ -50,6 +50,7 @@ export interface ReqResp extends ReqError { code?: string message?: string data?: any + id?: string resultsMapping?: ResultsMapping[] url?: string } diff --git a/apps/web/src/utils/analytic/analytics.ts b/apps/web/src/utils/analytic/analytics.ts index 1ae41003b..dbf3cd4d9 100644 --- a/apps/web/src/utils/analytic/analytics.ts +++ b/apps/web/src/utils/analytic/analytics.ts @@ -1,15 +1,9 @@ import Posthog from '@/utils/analytic/posthog' -import Cookie from '@/utils/cookies' -import { CookieValue } from '@/types/cookies' import Matomo from './matomo' export default class Analytics { - static sendEvent(action: string, name: string | null = null, value?: string | number | object | Record) { - const posthogCookie = Cookie.getCookieByValue(CookieValue.Posthog) - if (posthogCookie?.accepted) { - Posthog.captureEvent(action, name ? name : 'unnamed event', value) - } - + static sendEvent(action: string, name: string | null = null, value?: object) { + Posthog.captureEvent(name ? name : 'unnamed event', value) Matomo.sendEvent(action, name, JSON.stringify(value)) } } diff --git a/apps/web/src/utils/analytic/posthog.ts b/apps/web/src/utils/analytic/posthog.ts index 0a73a3496..aaa78630d 100644 --- a/apps/web/src/utils/analytic/posthog.ts +++ b/apps/web/src/utils/analytic/posthog.ts @@ -1,7 +1,5 @@ import posthog, { PostHog } from 'posthog-js' import Config from '@/config' -import Cookie from '@/utils/cookies' -import { CookieValue } from '@/types/cookies' import { RouteLocationNormalized } from 'vue-router' export default class Posthog { @@ -13,6 +11,7 @@ export default class Posthog { api_host: 'https://eu.i.posthog.com', capture_pageview: false, capture_pageleave: false, + persistence: 'memory', person_profiles: 'always' }) } @@ -20,22 +19,19 @@ export default class Posthog { static activatePosthogCookie() { if (this._posthog) { - this._posthog.opt_in_capturing() + this._posthog.set_config({ persistence: 'localStorage+cookie' }) } } static deactivatePosthogCookie() { if (this._posthog) { - this._posthog.opt_out_capturing() + this._posthog.set_config({ persistence: 'memory' }) } } static capturePageView(to: RouteLocationNormalized) { if (this._posthog) { - const posthogCookie = Cookie.getCookieByValue(CookieValue.Posthog) - if (posthogCookie?.accepted) { - this._posthog.capture('$pageview', { path: to.fullPath }) - } + this._posthog.capture('$pageview', { path: to.fullPath }) } } @@ -45,9 +41,9 @@ export default class Posthog { } } - static captureEvent(action: string, name: string | null = null, value?: string | number | object | Record) { + static captureEvent(name: string | null = null, value?: object) { if (this._posthog) { - this._posthog.capture(name ? name : 'unnamed event', { action: action, value: value }) + this._posthog.capture(name ? name : 'unnamed event', value) } } }