BLOG-112 Add Google Analytics integration and update environment variables #113
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "BLOG-112_install_ga"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
Package Changes
No response
Screenshots
Reference
Resolves #112
Checklist
/improve
PR Code Suggestions ✨
Avoid redefining the global
gtag
functionThe
window.gtag
function is defined by the Google Analytics script (gtag.js
) itselfonce it loads. Re-defining it in this component can override the official function,
leading to incorrect tracking or unexpected behavior. Ensure
window.dataLayer
isinitialized, and then allow the loaded
gtag.js
script to handle thegtag
function.frontend/src/lib/common/framework/ui/GoogleAnalytics.svelte [21-26]
Suggestion importance[1-10]: 9
__
Why: The suggestion correctly identifies that manually defining
window.gtag
can interfere with the official Google Analytics script, potentially causing tracking issues. Theimproved_code
accurately reflects the necessary change by removing the redundantgtag
function definition.09bae1126f
toe9b716521d
Defining gtag function is the sample code that Google provides:
However, the original implementation import the script with
<script lang="ts">
, so we have to define the type of function arguments. I remove the language restriction so that we don't have to define the function type by ourselves.Addressed in
e9b716521d
.