From 85128c85b8bb741f2d24e1a194dd0ba571c29bcd Mon Sep 17 00:00:00 2001 From: Lars Yencken Date: Tue, 9 Apr 2024 15:43:26 +0100 Subject: [PATCH] :bug: Fix analytics logging of search event parameters Currently BigQuery is receiving `[object Object]` instead of the JSON parameters. Here we stringify them first so that they get passed through. --- .../@ourworldindata/grapher/src/core/GrapherAnalytics.ts | 2 +- site/SiteAnalytics.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/@ourworldindata/grapher/src/core/GrapherAnalytics.ts b/packages/@ourworldindata/grapher/src/core/GrapherAnalytics.ts index 3720bab652d..43e8ca50201 100644 --- a/packages/@ourworldindata/grapher/src/core/GrapherAnalytics.ts +++ b/packages/@ourworldindata/grapher/src/core/GrapherAnalytics.ts @@ -41,7 +41,7 @@ type countrySelectorEvent = interface GAEvent { event: EventCategory eventAction?: string - eventContext?: string | Record + eventContext?: string eventTarget?: string grapherPath?: string } diff --git a/site/SiteAnalytics.ts b/site/SiteAnalytics.ts index d8837ddb625..9af87e4e533 100644 --- a/site/SiteAnalytics.ts +++ b/site/SiteAnalytics.ts @@ -41,7 +41,12 @@ export class SiteAnalytics extends GrapherAnalytics { this.logToGA({ event: EventCategory.SiteSearchClick, eventAction: "click", - eventContext: { query, position, positionInSection, filter }, + eventContext: JSON.stringify({ + query, + position, + positionInSection, + filter, + }), eventTarget: url, }) } @@ -58,7 +63,7 @@ export class SiteAnalytics extends GrapherAnalytics { this.logToGA({ event: EventCategory.SiteInstantSearchClick, eventAction: "click", - eventContext: { query, position }, + eventContext: JSON.stringify({ query, position }), eventTarget: url, }) }