Google consent mode and page views

AI-generated summary

vkalpias is implementing Google Consent Mode on their Discourse forum using the gtag.js library. To track page views, they need to send a page view event every time a user clicks on a post or topic. Falco suggests using a custom event hook as documented in meta.discourse.org. However, vkalpias is looking for a specific app event for page changes, rather than using Google Tag Manager. vkalpias eventually resolves the issue by installing a custom theme component and subscribing to the page:changed event, which was found by searching through the source code.

Hello,

We are trying to implement Google Consent Mode on our discourse forum. It ‘kinda’ works, we have disabled Google Analytics from the settings and instead changed the theme to include gtag.js manually and call the various gtag consent related calls in the expected order.

However how do we make sure that a pageview is recorded every time the user clicks on a post / topic etc? Is there an event we can subscribe to in the theme js where we can send a pageview on each page change?

Push custom events to Google Tag Manager and Analytics documents how to hook to many events to trigger functions.

Thanks I saw that page but that is using the Google tag manager. Is there an app event for a page change that I can use instead ? I see events for post created etc in that page but not page view or post view etc.

OK I think I fixed the issue. I installed a custom theme component and in the head I subscribed to the page:changed event which I found by grep’ing the source code.