We’re on a Google Analytics hacking kick, so we’re gonna keep it going for a little bit longer. This time, we’re going to add segmenting email lists to the mix. Because Mailchimp is awesome, we’re using them as an example, but this trick will work for any email marketing platform that lets you build your own web forms. What trick? A simple and awesome way to segment your mailing list using behavior data harvested from Google Analytics tracking cookies. And it will take all of 5 minutes!

Why would anyone in their right minds want to segment their email lists with Google Analytics? Well, to be completely honest, if you aren’t running a fairly sophisticated email marketing program, it doesn’t really matter. If you batch and blast, and you don’t plan on changing your horrible ways anytime soon, you may as well not take the time to set this up. If you DO segment your list, though, or you plan on starting very soon, and you want to send timely, relevant, and useful emails (you DO want to send timely, relevant, and useful emails, don’t you?), then continue reading.

We’re going to assume you’re a smart marketer and you want your email to really convert. So the question now is how do you find out what your audience finds relevant? Well, you can make an educated guess. You can, for instance, assume that generally whatever your website is about is of interest to the people that willingly give you their email address. You can pore through your analytics data and try to identify were your traffic came from, what they were looking for when they got to your site, what page they landed on, where they went after that, etc. Unfortunately, unless you’re using one of the ESPs that integrate very closely with Google Analytics, you won’t have any way to track individual subscribers. Aggregate data is good, individual data is better. With the method I’m about to show you, you can tie these things directly to your email list subscribers, and then use the segmentation functions in your ESP to build more awesomer emails. Ready? Me neither, but let’s go anyway.

Step 1: Set Up Your Email List

Some ESPs let you generate new fields dynamically. Mailchimp is not one of them. They like for all your fields to be set up in their back-end before you go futzing with them. So our first step is to create a couple of new custom hidden fields in your Mailchimp list. The options to add fields to your list is in the form builder. I won’t go through the step-by-step because a) you should already know this, b) directions already exist on Mailchimp’s site and elsewhere, and c) I don’t want to get caught up in specifics.

The fields you want to add are:

  • “Source” – The visitor’s source
  • “Campaign” – Campaign name that brought the visit in (if tagged)
  • “Medium” – The medium for the visit
  • “Term” – Term that user searched for to bring them in (will usually be (not provided). Sigh.)
  • “PContent” – The specific piece of content the form was submitted from  (the URL), and
  • “CContent” – The campaign content tag

Make sure you add these fields as hidden fields, otherwise they’ll show up when you go to generate a form. Keep in mind this entire process might be completely different for YOUR ESP if you don’t use Mailchimp. Read up on it, and follow the steps that work for your software.

Step 2: Generate a Form

Mailchimp makes this ludicrously easy. From the top menu on the “Create Forms” page, select “Signup Form Embed Code” from the “For Your Website” dropdown menu. Pick whatever kind of form floats your fancy (I’m a big fan of “super-slim”), and copy the provided code. This is the HTML you’re going to be messing with to generate segment data. It should look something like this:

<!–End mc_embed_signup–>
Easy enough so far, right? Now comes the fun part. We’re going to add PHP too.

Step 3: Pulling Cool Info From the GA Cookie and Adding It To Our Form

Remember those hidden fields we created earlier? It’s time to add them to our form. Here’s the code you’re adding:

Now we’re going to fill those values up, and that’s going to require PHP. Hooray PHP. I’m going to borrow an excellent script for parsing the GA __utmz cookie from Roger’s blog:

What does all that do? It pulls apart GA’s campaign tracking cookie (__utmz) and extracts the gooey data inside, then stores it in a PHP array called “$utm”. We’re going to take this data and populate it into our hidden fields, and then slap those hidden fields into our Mailchimp form code:

<!--End mc_embed_signup-->

Ta Da! All new subscribers will have information in your Mailchimp database about how they got to your site, what they were looking for, and what page they actually signed up for.

This used to be a lot more powerful before Google started blocking keyword data access for signed-in searchers, but it’s a good place to start segmenting. Especially if you use descriptive URLs which can be searched easily for keywords.

Leave me a comment if you found this post useful, and let me know if you want any functionality added. I’ll try to update things occasionally.

Special Note:

It has been pointed out by a couple of people that you really shouldn’t be pulling this information out of your Google Analytics cookie. “What if”, the naysayers naysay, “What if Google changes their cookie format? Then you’re screwed!” Which is a fair point. Ideally, you should be getting information from your own server. But that’s more of a pain in the ass. Anyone that is going to actually take time out to build their own tracking scripts isn’t going to need this blog post; they already know what they’re doing. And if Google changes their cookie format, we’ll just go ahead and update the script. The world isn’t going to end.

Pin It on Pinterest