Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
539 views
in Technique[技术] by (71.8m points)

reactjs - Google Analytic GA4 does not disable default page_view event in React Application

I'm trying to add Google Analytics GA4 to a React Application,

index.html

   <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', 'G-xxxxxxxL', {send_page_view: false});
    </script>

Except that this does not disable the default page_view event.

I would like to disable the default request so I manually send page_view events. they are some pages where the title is not set unlike a saga returns, for example: Project: . the default event sets to undefined, which make sense because data is not loaded yet.

So I how can I achieve this?

question from:https://stackoverflow.com/questions/66066520/google-analytic-ga4-does-not-disable-default-page-view-event-in-react-applicatio

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try toggling the option to automatically track history events as page cries OFF from the Enhanced Measurement settings in GA4 admin (Web Stream settings).

Many SPA sites have an initial pushState/replaceState in place for state management purposes (or for other reasons), which would cause a page_view to be tracked of that Enhanced Measurement option is toggled on.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...