Adding analytics to a component is pretty straightforward,
First set up your analytics object in your composition
method:
Then import the track
object from src/lib/Analytics
into your component, and grab the analytics
data from the composition props. After that, simply attach a handler to the correct component node, to call the track.component
method and send the data to analytics:
When not in production, analytics data will be sent to the console instead of to Google. To verify that your analytics are being setup and used correctly, simply open the console, trigger the analytics method, and you should see something similar to the following:
Intro | Technical Overview | Practical Overview | Typescript | Sitecore | Definition of Done | Analytics