datamade / bga-payroll

💰 How much do your public officials make?
4 stars 4 forks source link

add google tag manager with download data event tracking #581

Closed smcalilly closed 2 years ago

smcalilly commented 2 years ago

Overview

For issues:

Notes

This new setup requires some orchestration between the new-ish Google Tag Manager console and the familiar Google Analytics console. It took more time than expected to figure it out, but I understand it now (somewhat). GTM provides non-technical users a way to setup Google Analytics event tracking within the GTM admin console, without making any code changes.

Google Tag Manager console

I followed this guide to implement the click tracking.

In the Google Tag Management console, I created two triggers:

  1. Download Source Data Event
  2. Download Standardized Data Event

Both of these triggers are attached to the same Download Data Event Tag.

Google Analytics console

When a user clicks on either of the links for the triggers, it will log in Google Analytics with the download_data_event.

Screen Shot 2021-11-22 at 11 37 41 AM

BGA users will be able to distinguish between the download triggers (standardized data vs source data) with the help of values in download_data_text and download_data_url. We can separate these two triggers to have their own tags if we want, but for this iteration all download events are tagged as a download_data_event.

Note that the Google Tag Manager in GA4 tracks file downloads by default. I turned this off since I thought it would be confusing to have two different file download event types, and decided to consolidate under this one custom download_data_event. Also, the source file was the only download tracked by this, since the new data download requests the server and doesn't have a filename (which is used by GA4 to determine if it's a file_download event)

Testing

fgregg commented 2 years ago

Very cool.