Skip to content

Add Google Analytics#51

Draft
azaddhirajkumar wants to merge 1 commit intomainfrom
Add-Google-Analytics
Draft

Add Google Analytics#51
azaddhirajkumar wants to merge 1 commit intomainfrom
Add-Google-Analytics

Conversation

@azaddhirajkumar
Copy link
Copy Markdown
Contributor

Following the same pattern followed on Developer Portal: https://github.com/couchbaselabs/developer-portal/pull/712
to add google analytics to the ionic website.

@azaddhirajkumar azaddhirajkumar changed the title Add Google analytics Add Google Analytics Apr 1, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds Google Tag Manager (GTM) tracking to the Docusaurus configuration by injecting a script into the head tags. The review feedback highlights that manual injection may not capture SPA navigation events and recommends using the official Docusaurus GTM plugin instead. Additionally, it is suggested to include a fallback in the body tags to support users with JavaScript disabled.

Comment on lines +31 to +35
innerHTML: `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//metrics.couchbase.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-MVPNN2');`,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Docusaurus is a Single Page Application (SPA). Manually injecting the GTM script via headTags only executes on the initial page load. Subsequent in-app navigations will not trigger 'Page View' events in GTM unless the container is specifically configured with 'History Change' triggers or a clientModule is used to push events to the dataLayer (similar to how scarfAnalytics.js handles route updates).

Consider using the official @docusaurus/plugin-google-tag-manager which handles SPA navigation automatically and is the standard approach for Docusaurus sites.

'//metrics.couchbase.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-MVPNN2');`,
},
],
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The Google Tag Manager implementation is missing the recommended <noscript> fallback component. This should be placed in the <body> to ensure tracking works for users with JavaScript disabled. You can use the preBodyTags configuration in Docusaurus to inject the GTM iframe snippet immediately after the opening <body> tag.

Suggested change
],
],
preBodyTags: [
{
tagName: 'noscript',
innerHTML: '<iframe src="https://metrics.couchbase.com/ns.html?id=GTM-MVPNN2" height="0" width="0" style="display:none;visibility:hidden"></iframe>',
},
],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant