Complex eCommerce Tracking in Nationbuilder

The tech used in this post is outdated, but the solution is the same. In the future I'll update this article with an implementation for GA4.

The goal of this setup was to (as accurately as possible) report Nationbuilder donations to Google Analytics.

Developers note: the snippets in this post are from an older attempt to do eCommerce tracking in GA. They were done under conditions that no longer apply in some circumstances, specifically:

  1. We were using Universal Analytics at the time. Both GA4 and Google Tag Manager are better tools to solve this problem now.
  2. Some of the early code was written before Nationbuilder supported full site SSL certificates -- so we had to configure our donation page URLs as cross-domain tracking. That is no longer an issue.

If nothing else, the logic written in Liquid may be useful when trying to implement this going forward.

The basic structure of what is happening here is this:

  • There is some small code (not shown) that is only on donation page templates. When a donation is made it does one thing -- captures a unique ID and attempts to grab the donation amount that was just made and it stores those items into the localStorage object/cookie. Then that form (using Nationbuilder settings) redirects to a thank you page like normal.
  • The snippet above is what is included on the thank you page. It first grabs any data that we might have sent to localStorage before.
  • The code attempts to grab some things about the current user from the "request" Liquid object
    1. most recent donation ID
    2. most recent donation amount
  • For several reasons and for some I don't quite understand, grabbing that info from Nationbuilder's "request" object failed pretty commonly so then we fall back on what we stored in localStorage.
  • The else part of the loop grabs the localStorage ID and Amount and sends that to Analytics instead.

The end result of this is a list of unique transactions in Google Analytics that were either identifiable by their Nationbuilder donation ID or our unique ID we assigned to that donation. Regardless of which, it gave us a universe of donations directly attached to a GA session id and the benefits that come with that; acquisition data included.