I am relatively new to using Google Tag Manager (GTM), and I am trying to figure out the best way to log Custom Events from a single page app built with React. I want these events to register in Google Analytics (GA) which I have set up already in Google Tag Manager. The kinds of events I'm planning to record are user account creation, email validation, user sign in, user sign out, and various other interactions within the application. It looks like there are various ways to trigger events based on form submissions using Google Tag Manager, but I thought it would just be simpler to manually "invoke" each event I want exactly where I want it via the GTM API.
Searching the web, this was the most useful tutorial I found: Google Tag Manager Custom Event Trigger Explained by Julius Fedorovicius. I made a spreadsheet for my app to capture all the custom events I am interested in. There were 26 of them. As I followed the tutorial, I noticed the following things I would need to do:
- Create and push various Variables into the GTM Data Layer to use them in my event labels and values.
- Create a new GTM Trigger for each of the 26 custom events from my spreadsheet
- Create a new GTM GA Tag and associate the corresponding trigger for each of the 26 custom events from my spreadsheet
Step 1: Create Data Layer Variables for each possible GA Event field
Step 2: Create a Custom Event Trigger
Step 3: Create a Custom Event Tag and Associate with Custom Event Trigger
Pushing Events to Google Tag Manager
<script> window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'event': 'Custom Event', 'eventCategory': 'My Event Category', 'eventAction': 'My Event Action', 'eventLabel': 'My Event Label', 'eventValue': 0 }); </script>