Check out example codes for "set up google analytics". It will help you in understanding the concepts better.

Code Example 1

How to set up Google analytics:

Watch this video: https://www.youtube.com/watch?v=lZf3YYkIg8w

Or Click on this link: https://support.google.com/analytics/answer/1008015?hl=en

Learn ReactJs, React Native from akashmittal.com