Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
535 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...