TURI BLOG

[GA4] Initial Code Snippets to Apply to Google Analytics 본문

[TIL]Today I Learned

[GA4] Initial Code Snippets to Apply to Google Analytics

TURI BLOG 2024. 1. 2. 16:15

Initial Code Snippets to Apply to Google Analytics


 

My task was to set up the initial stage of Google Analytics for the website to analyze user behavior and needs in the future.

 

The challenges encountered:

  • Uncertainty about the difference between react-ga and react-ga4
  • Uncertainty about how to apply react-ga4 to the code with the existing initial GA measurement ID, including the initial setting on the code
  • What and where to apply for Google Analytics tracking

My approach to tackling these challenges:

  1. Installed react-ga4  instead of react-ga
  2. Created an account on Google Analytics and linked the existing measurement ID to the new accounts' tag
  3. Tested on local with Google Analytics's Preview environment
  4.  Applied and tested the code on button events that don't change the URLs

Here's my approach:

1. Installed react-ga4 instead of react-ga

I believed it was necessary to use react-ga4 for the website, especially if we aim to collect and analyze specific events, not only universal data.

 

https://stackoverflow.com/questions/62135901/reactga-not-working-for-g-type-tracking-id

 

2. Created a new account in Google Analytics and linked the existing measurement ID to the new accounts' tag

I encountered difficulties accessing tag managers and testing preview environments, as shown in the official YouTube video

 

As a workaround, I created a new account and linked its tag to the existing measurement ID

 

3. Tested on local with Google Analytics's Preview environment

 

4. Applied and tested the code on button events that don't change the URLs

 

 

 


Code snippets & questions :

However, I was uncertain about creating customized events on Google Analytics 4 using tag managers.
The final code for the initial setup involved adding event parameters instead of utilizing customized events. 

 

 

https://support.google.com/analytics/answer/13675006?hl=en

 

[GA4] Event parameters - Analytics Help

An event parameter is an additional piece of data about a user interaction on a website and/or app, offering valuable context and details about the interaction. By using the data from an event parameter, you can dissect user behavior with a high level of g

support.google.com

 


Therefore, the process of creating a new account and linking the existing measurement ID to its new tag was not applied to the current analysis code state.

 

And I am wondering

what the specific cases are that require customized event tags.

 

 


 

Comments