NationBuilder works well with Google Analytics

Tracking Signups as Goals in NationBuilder

If you are trying to connect with supporters of your cause, NationBuilder is incredibly powerful software for the price.   And Google Analytics is incredibly powerful web analytics software at any price (though it happens to be free).

In this tutorial I am going to show you a very important step in using Google Analytics with NationBuilder: tracking NationBuilder website conversions as goals in Google Analytics.

Get better at using NationBuilder and Google Analytics

I am going to assume you have set up a NationBuilder site, and installed Google Analytics to track your site visits.   You are using it to tell you things like how many people come to your site, and what pages they look at most often.

If you want to make the most of Google Analytics, you need to start tracking your most valuable visitors to your site.   People who sign up to volunteer, sign a petition, share the site on social media or take a survey.   These high value visits are often referred to as ‘conversions’.   These visitors are the ones you built the site for, and you want to know how to get more of them.

A key technique in web analytics is conversion tracking – tracking the visitors who take the most valuable actions on our site.   (The other two key techniques are campaign tracking and audience segmentation FYI)

In this example I am going to walk you through how to use Google Analytics to track conversions as ‘goals’ in Google Analytics.

Tracking NationBuilder petition signatures as goals in Google Analytics

As an example, I am going to show you how to set up NationBuilder and Google Analytics to track visitors who sign a petition on your Nationbuilder site.

Here is what I am assuming:

– You have a NationBuilder site with Google Analytics installed (and haven’t upgraded to Universal Analytics).
– You (or someone you know) can edit the template files for your NationBuilder theme.
– You have   (or someone you know has) administrator access to your Google Analytics account, so you can set up goals.

Ready to get started?   There are two basic steps involved:

  1. Edit some code on your petition page(s)
  2. Create a goal in Google Analytics to track petition signatures

Step One : Edit some code in your NationBuilder petition template

As you likely know, each page type in NationBuilder is represented by a template file.   You can edit these template files by logging in to your Nation site and going to:

Websites > Name of your Website > Theme

You will see a long list of the theme template files, each one determining what appears on each type of NationBuilder page in your site.     Since we’re looking to track petition signatures, we want to edit the files called :

pages_show_petition.html

pages_show_petition_wide.html

These pages determine how each of our petition pages looks and operates.   They have different conditional tags – if petition is signed, if petition has a goal, if comments are enabled – that show different content depending on current conditions.

We want to go add some code to the section that checks to see if the petition has been signed by this person.   The code looks like this on the template page I am editing –  pages_show_petition.html

 The {% if page.petition.is_signed? %} tag in NationBuilder - we put some javascript after this.

We are going to add four lines of javascript shortly after we see that conditional tag.   It’s best to install it directly after that conditional code – otherwise it could get caught up among other condition codes.

Here’s the script you are going to paste, copy and paste it EXACTLY as any small glitches and it won’t work:

  <script type="text/javascript">
  var _gaq = _gaq || [];
    _gaq.push(['_trackEvent','Petition','Submitted','{{page.title}}']);       
  </script>

Here’s where I pasted my code, directly after the conditional tag
{% if page.petition.is_signed? %}

The javascript code I inserted into the petition template page, just after the conditional statement to see if the petition was signed.

In case you’re curious, these four lines of javascript say the following:

“Hey, this is javascript
If Google Analytics doesn’t have it together yet, don’t worry, carry on
Tell your Analytics account that a Petition was Submitted from a Page with this Title
javascript out”

Save that petition template and you are done.

Now when someone signs a petition on your site, a message will be sent to your Google Analytics account, letting it know that the petition was signed.  If you are using the other petition templates, repeat this process on all petition page templates.

The next step is to set up Google Analytics to record that event in a particular way – as a goal in Google Analytics.

 

 Set up an event goal in Google Analytics

We’re going to log in to Google Analytics and set up what’s called an ‘event goal’.   That script we put on our petition pages triggered a javascript event with particular values attached to it – Petition, Submitted, and (Page Title)

We’re going to set up our Google Analytics view to track when an event happens on the site with those values. Here’s how:

Log in to your Analytics account, click on the ‘Admin’ link on the top navigation bar, and make sure you are in the right Google Analytics view, the one that’s tracking your NationBuilder site.   Here’s what I see, when I log in to Admin, and want to work with ‘Production Site 2’.

This is the admin panel in Google Analytics. It will look different next week.

Click on ‘Goals’ link, then + NEW GOAL

New Goal button, now in Red.

Give the goal a name, and choose “Event Goal” if it’s available, or “Custom” if you see a confusing jumble of nonsensical options.   (“Custom” is the last option, at the bottom). Custom allows you to select “Event” as the type of goal to create.

Give your goal a name, and choose "Event" if it's an option, "Custom" if it's not.
Choose “Event” as the goal type, “Custom” and then “Event” if not.

Now you are going to enter the values your goal is going to be listening for.   Remember these are Petition (that’s the event Category) and Submitted (that’s the event Action)   You can click on “Create Goal” now if you want – you’re done.

Event category is "Petition' and event Action is "Submitted'.

(You don’t need to specify a Goal Value (it’s not that useful right now) and since you just started listening for this event, if you “Verify” the data, you likely won’t have any conversions.)

Now you’re done.

Testing, and tracking a particular petition

If you’re curious to see how this tracking is working, you can log in to Google Analytics and the Real Time report (top of the left column) and then click on Conversions.   If you go and sign the petition and wait a few seconds, you should see your Petition conversion show up in the Real Time dashboard.

The Real Time report and the Conversions (or Events) tabs will show your petition signature in real time. Great for testing.
The Real Time report and the Conversions (or Events) tabs will show your petition signature in real time. Great for testing.

 

Google Analytics just got 1000 times better

So why make all these modifications to your site?

Why bother setting up goals when you already know how many people sign your petitions, and what their names are?

Here’s why:

NationBuilder tells you how many people signed your petition, and what their names are.

Google Analytics, once you’re using it properly, tells you:

  • Which particular email, tweet or online ad led to the most signups
  • How many times they came to your site, and from where, before they signed
  • What people did before and after signing your petition
  • How often your Facebook visitors sign up, compared to those who visit from search, twitter or your email list
  • What days, age groups, cities and operating systems are most likely to result in petition signatures

Want to learn how to do that?   I have put together five free lessons to teach you these important web analytics skills.   Sign up here (Did I mention the lessons are free?)

Get The Ultimate Guide to Using Google Analytics with Nationbuilder  Over the next few weeks I will be putting together a step-by-step guide to using Google Analytics with Nationbuilder. Get it for free when it’s ready by signing up here

Looking for help with your NationBuilder Nation?   Check out my friends at C Street – they build beautiful, effective sites that help progressives win campaigns.

Have questions about this process? Ask in the comments below.