Skip to content

Commit 6f72514

Browse files
committed
Added documentation on custom event set up
These docs existed in Google Docs before, but I wanted them in the shared NJIA docs for everyone to be able to consume / edit. I've purposefully avoided any direct links to our resources or emails.
1 parent 0b2e2c1 commit 6f72514

1 file changed

Lines changed: 106 additions & 5 deletions

File tree

src/content/docs/guides/monitoring/setting-up-google-analytics.md

Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,117 @@ For testing, make sure any adblock is turned off.
2727
6. Confirm via the “Preview” that the [GA4 ID is being fired correctly](https://support.google.com/tagmanager/answer/6107056?hl=en). You can also check this in the [“Realtime” analytics](https://analytics.google.com).
2828
7. **Optional**: Manage your event tagging
2929
- Many things will already be automatically captured, such as [users, sessions, and views](https://support.google.com/analytics/answer/9234069?hl=en)
30-
- [If you require custom events, follow these instructions](https://support.google.com/analytics/answer/12229021?hl=en)
31-
- General steps:
32-
- Align on event definition and parameters as a team. Note: Documenting the custom event names and parameters in a spreadsheet can help the team stay aligned on what events are being tracked and implemented from code to GTM. For an example, see the AI Assistant tracker, particularly columns G and H.
33-
- Engineering to implement the events within the application’s JavaScript code
34-
- Then, PM or Engineering can configure the tag and triggers within GTM
30+
- [If you require custom events, follow the instructions below](#setting-up-custom-google-analytics-events)
3531
8. Once the GA ID and any desired custom event tracking is added, email [OIT web publishing](https://docs.google.com/document/d/1MNDEx6Oabu5CxrgqMnhFpO9XDX-LTYjNNTw6qGNwqKM/edit?tab=t.0#heading=h.k89ioaydzbt3) to publish the tag. This step is important; without this, you will not capture analytics.
3632
- They typically have a quick turnaround, within a few hours to a day, but make sure to build in some time here ahead of launch.
3733
9. It will take 24-48 hours for analytics reports to start populating, but to confirm the tags once they are live, you can use the “Realtime” reporting within Google Analytics.
3834
10. For custom dashboards, Looker Studio dashboards can be set up (by Engineering) after Google Analytics is implemented and added (note that it takes 24-48 hours to start seeing new events in Looker). In the meantime, you can see analytics reporting within Google Analytics itself. For an example, see the AI Assistant Looker Studio dashboard
3935

36+
## Setting Up Custom Google Analytics Events
37+
38+
Here are detailed instructions on how to set
39+
up [a custom event](https://support.google.com/analytics/answer/12229021?hl=en).
40+
41+
### Step 1 - log event in app
42+
43+
The specifics depends on the app, but basically you will log events w/ an event name & (optionally) some associated
44+
parameters. For example, you might log the event `downloaded_file` with the parameter `{ object_size: 4096 }`.
45+
46+
#### Tips for event definition
47+
48+
**Align on event definition and parameters as a team.** Documenting the custom event names and parameters in a
49+
spreadsheet can help the team stay aligned on what events are being tracked and implemented from code to GTM. For an
50+
example, see the AI Assistant tracker, particularly columns G and H.
51+
52+
**Try to keep event parameter names generic** (e.g. `object_count`
53+
instead of `file_count`). That way, they can be reused across multiple custom events (since GA4 has a limit of 50
54+
event-scoped custom dimensions).
55+
56+
**Do not create unnecessary [high-cardinality custom dimensions](https://support.google.com/analytics/answer/12226705)**
57+
(more than 500 unique values in one day). For example, a parameter recording unique user IDs, session IDs, timestamps,
58+
etc. You can
59+
find [more info on custom dimensions here](https://support.google.com/analytics/answer/14240153?hl=en).
60+
61+
### Step 2 - configure event in GTM container
62+
63+
**Create a new workspace**
64+
65+
1. Go to [the NJIA GTM container](https://tagmanager.google.com/).
66+
2. Create a new Workspace to make your changes in.
67+
1. This helps OIT to publish just our changes when the time comes. If all 3 workspaces are taken you can make changes
68+
in the Default Workspace.
69+
70+
**Create a new Variable (if necessary)**
71+
72+
1. In the "Variables" tab in the sidebar, check whether the event parameter(s) you're using already exist.
73+
2. If the parameter doesn't exist, create a new variable:
74+
- Title the variable (e.g. "Object count").
75+
- Click the folder icon next to the title and select your project's folder.
76+
- **Variable type:** "Data Layer Variable"
77+
- **Data Layer Variable Name:** the property name of the event parameter (e.g. "object_count")
78+
- **Data Layer Version:** "Version 2"
79+
- Configure other options as needed
80+
81+
**Create a new trigger**
82+
83+
1. Go to the "Triggers" pane in the sidebar > click the "New" button
84+
2. Title: "[project] - [name]"
85+
- Click the folder icon next to the title and select your project's folder.
86+
3. Click "Trigger Configuration" and select "Custom Event" as the trigger type
87+
4. **Event name:** The name of your new event
88+
5. Leave the "All Custom Events" radio button selected.
89+
90+
**Create a new tag**
91+
92+
1. Go to the "Tags" pane in the sidebar > click the "New" button.
93+
2. Title: "[project] - [name]"
94+
- We recommend using the same title as the trigger you just created.
95+
- Click the folder icon next to the title and select your project's folder.
96+
3. "Tag Configuration" section
97+
1. Select "Google Analytics" > "Google Analytics: GA4 Event" for the tag type.
98+
2. **Measurement ID:** The measurement ID of your Google Analytics property (see other custom events for examples).
99+
3. **Event Name:** the name of your new event (e.g. upload_files_error_file_count)
100+
4. Under the "Event Parameters" section, click the "Add parameter" button
101+
102+
- **Event Parameter:** the property name of the parameter (e.g. object_count)
103+
- **Value:** click the add variable icon (lego button with a plus sign) and select the variable you created in the
104+
previous step.
105+
4. Click the "Triggering" section and select the trigger you created in the previous step.
106+
107+
### Step 3 - test new event
108+
109+
1. Run your app locally.
110+
2. In the GTM container, click the "Preview" button in the toolbar. This will open the Tag Assistant.
111+
3. Enter the local dev URL as the website URL
112+
4. In the new window of the app that opens, test the interaction that should fire the custom event.
113+
- You should see the event fire on the Tag Assistant page. Also check that the event parameter(s) come through as
114+
expected in the "variables" tab.
115+
- Check that the GA4 event successfully fires under "Tags" of the GTM container. Also click into the card in order to
116+
confirm that the event has been sent to the correct GA tag with the expected event parameters.
117+
118+
### Step 4 - Add custom dimensions to GA4 (if necessary)
119+
120+
If you created a new event parameter, then we need to add a custom dimension for each new event parameter to the GA
121+
property in order for it to show in the dashboard.
122+
123+
1. From the GA property dashboard, go to the Admin section (the gear icon at the bottom of the sidebar).
124+
2. Under the "Data display" settings section, click "Custom definitions"
125+
3. For each new event parameter, click "Create custom dimension"
126+
- **Dimension name:** use the same name as the GTM Variable (e.g. "Object Count")
127+
- **Scope:** "Event"
128+
- **Event parameter:** the property in extraParameters (e.g. "object_count")
129+
4. If you use the Tag Assistant to preview the changes to GTM again, you should now see your events appear in the GA
130+
dashboard as well.
131+
132+
### Step 5 - Request to publish the GTM changes
133+
134+
Send an email to [OIT web publish](https://docs.google.com/document/d/1MNDEx6Oabu5CxrgqMnhFpO9XDX-LTYjNNTw6qGNwqKM/edit?tab=t.0#heading=h.k89ioaydzbt3) requesting for your changes to the GTM container to be published.
135+
136+
Make sure to:
137+
138+
- CC operations@[OIT domain] for visibility
139+
- Include the name of the Workspace containing the changes to be published
140+
40141
## Best Practices
41142

42143
- Test any changes using the “Preview” functionality

0 commit comments

Comments
 (0)