How to set up Google Analytics through Google Tag Manager for Next-Js?

后端 未结 6 980
北恋
北恋 2021-02-13 16:24

formerly I was using react-ga npm module to insert google analytics in my next js app. and It was simply like this:

import ReactGA from \'react-ga\'

export cons         


        
6条回答
  •  暖寄归人
    2021-02-13 16:41

    In order to use Google Tag Manager you should inject your tag manager script on every page. since _document.js is the wrapper for every page, you should add the GTM script to _document.js in the head section like this:

    
      
      ...
    
    

    Now you are all set to use Google Tag Manager in your next-js app. You should only proceed to handle pageview and other analytics related stuff from your GTM dashboard.

    To set up google analytics pageview for single page applications(like nextjs) you can follow these steps.

提交回复
热议问题