Developing a Google Analytics plugin
In the following pages, I will assume that you are familiar with Google Analytics and that you have correctly configured Google Analytics tracking in your application. If not, you can Google it, understand how it works, and come back here. A basic understanding is more than enough to proceed with the following pages.
The first step is to add this Google Analytics tracking code snippet to the index.html
file:
<!-- index.html --> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'GA_TRACKING_ID'); </script>
After that, a global gtag(...)
function will be available to send events to Google Analytics servers.
Typically, an application tracks page views and some events. To send an event to...