简体   繁体   中英

Using analytics.js without react-ga

I want to integrate google analytics into my react app without using the react-ga package. Specifically, I would like to be able to access the ga function in a separate javascript script and possibly within a react component. How do I get access to the ga function in a separate javascript file if I import the analytics.js script into my html?

 console.log(ga.q) 
 <script async src='//www.google-analytics.com/analytics.js'></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

ga and gtag (if you want to use it instead of ga, that I recommend it) are both accessible using window:

window.ga()

window.gtag()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM