- 30 Jan 2024
- 4 Minutes to read
- Print
- DarkLight
- PDF
Tracking SendGrid Email Campaigns using Google Analytics
- Updated on 30 Jan 2024
- 4 Minutes to read
- Print
- DarkLight
- PDF
Google Analytics (GA) is a great free resource that helps you stay on top of your website's performance. But did you know GA is also useful for monitoring your outbound emails? In this post, we'll show you how to use Google Analytics email tracking to gain statistical insight into your campaigns. Plus, if you're a Twilio SendGrid user, you'll learn how to use our REST API to simplify the process.
Tracking conversions from your email campaigns will help you understand how your emails perform and how to improve them. Follow these steps to learn how to generate a URL for an email campaign and track conversions in GA.
1. Sign up and install Google Analytics
First, head to GA to sign up and integrate the tracking code into your website as directed. To obtain the results described in this post, you must verify that you have properly set up your GA account.
2. Generate a URL to track inbound traffic from emails
With Google Analytics 4, the latest version of GA, you can track clicks on your email campaign by creating Events and marking them as Conversion events. To do so, add query parameters to the end of your URL, then use GA to mark any page views with those query parameters as conversions. This helps you distinguish between visitors who arrived at your site through an email campaign and visitors who arrived by other means.
For example, let's say you want to drive traffic to a specific page on your site: https://www.example.com/weekly-specials
. You can add query parameters of your choosing, such as campaign_id
, and give the URL a distinct value for your email campaign. The resulting URL to use in your email might look like this:https://www.example.com/weekly-specials?campaign_id=winter-campaign-01
3. Set up a conversion event for your email marketing campaign
You need to set up a Conversion event in GA to track conversions. In the sidebar navigation, click on Configure. Then go to the Events page.
On the Events page, click the Create Event button.
Now, give your event a name. For example, winter_campaign_email_clicked
. Next, set the conditions that indicate this event has occurred. For our custom event example, we have two conditions:
- The
event_name
will bepage_view
. - The
page_location
(the referring link that brought the user to your site) will containcampaign_id=winter-campaign-01
(Our unique query parameter distinguishes our email campaign.)
Click Create.
Next, go to the Conversions configuration page. Select New conversion event.
In the New Event Name field, enter the name of the custom event you created. For our example, that's winter_campaign_email_clicked
.
Click Save.
Now, you can track each conversion from your email marketing campaigns in GA, giving you valuable insights into how your emails perform.
4. Use the Twilio SendGrid API to send emails with custom URLs
The Twilio SendGrid REST API allows you to build an email program customized to your business. To track your email campaign conversions with this API, you'll use the custom URL generated in GA. Plus, you can use several language SDKs to integrate email with your projects easily.
Let's look at how to send an email using Twilio SendGrid with the custom email campaign URL link embedded. First, you'll need to sign up for a free account. Shortly after you sign up, you'll receive a verification email informing you when your account is active.
For our demonstration, we'll use Twilio SendGrid's Node.js SDK. To get started with the SDK, initialize a new Node.js project, then add the @sendgrid/mail
package:
~/project$ yarn init ~/project$ yarn add @sendgrid/mail
Next, save this code as a file called index.js
And put it in your project folder. Because this is an example mail-sending application that you run at the command line, you'll need to include a few environment variables when running the application:
API_KEY
: This is your Twilio SendGrid account API key.CUSTOM_URL
: This custom URL for your email campaign directs users to your site and includes your unique query parameter.RECIPIENT_EMAIL
: This is the recipient's email address. (When testing, use an email address you can access so that you can verify you received the email and click the campaign link inside.)
Below is an example of how to run this application from the command line:
~/project$ API_KEY=INSERT-YOUR-API-KEY-HERE CUSTOM_URL=https://www.example.com/weekly-specials?campaign_id=winter-campaign-01 RECIPIENT_EMAIL=INSERT-YOUR-EMAIL-ADDRESS-HERE node index.js
This application won't work until you activate your Twilio SendGrid account.
After you've run the above application, you should receive an email in the inbox you entered for RECIPIENT_EMAIL
. GA will count this as a conversion when you click on the URL within the email. Next, we'll look at how to view these conversions in GA.
5. Examine the data in Google Analytics
When your email recipients click on your campaign URLs, GA records those clicks in your statistics. To track these clicks, go to Reports in the GA navigation. Then, select Realtime.
You'll see tables for Event count and Conversions by Event name here. (GA captures many different events by default.) As your site sees more activity on your site, including email campaign link clicks, more entries will show up in the Event count table. However, only those events you marked as Conversion events will appear in the Conversions table.
You’llYou'lll, we defined a winter_campaign_email_clicked event and added it as a Conversion event. After clicking on the campaign link in the email you received, you'll see a new conversion event in the realtime report: