Adding Google Analytics to your emails

Step by step, how-to add Google Analytics to your emails and get all the information from Google.
Web Google Analytics Email Marketing Online SEO Webapp Website

You have a new product, a new app or a new website. You want to make it known by other people and customers so you've decided to run an online marketing campaign using emails. You have the email you're going to send ready because you have read our post and you have decided to do it on your own but you would like to know how is working your campaign and who has opened your email, where, when, ... For that you know Google Analytics is perfect, you already have an account but you don't know how to use it with your emails. Let me explain you how it works.

Crear Email

I assume that you know you have to send an email with HTML content, that you have already designed it and you have the email ready to send.

To add Google Analytics, as it was a website we need to add a small script to the head meta tags of our email. This is what Google calls tracking code (or similar) and it's so easy to get from your Google Analytics account. You just need to go to your Google Analytics account, go to the Administrator tab and inside this tab to the div Property that you want to use, go into Tracking Information -> Tracking Code and there you have to copy the code shown, something similar to:

                                        <script>
                                            (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
                                            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
                                            m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
                                            })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

                                            ga('create', 'UA-12345678-1', 'auto');
                                            ga('send', 'pageview');

                                        </script>
                                    

Once you copy and paste this code to the head tags on your email we'll have most of the job done.

To register that someone has opened your email, you need to register it as a Google Analytics Event. This is really easy to do. The recomendation from Google is to add an image to your email code with the actual code for your event. This image will be invisible, only 1x1px and it's recomended to add it to the end of the email, right before you close the html tag.

                                        <img src="https://www.google-analytics.com/collect?v=1&t=event&tid=UA-12345678-1&cid=1dd0f208-6cdb-4ac1-81cc-5a409869d10a&ec=email&ea=open&dt=MatchUp%20Padel&ul=en-US&cm=email&cs=%28direct%29&cn=%28MatchUpPadelEmail%29&ck=MatchUpPadel%20Email"/>
                                    

The source for this image has a link to the event you're going to register in Google Analytics and you can add a lot of different information to as precise as you want and collect as many information as you want. Some of the most important fields are:

  • v: [REQUIRED] always "1".
  • t: [REQUIRED] type of the hit, in this case "event".
  • tid: [REQUIRED] tracking id of the web property.
  • ec: [REQUIRED] event category.
  • ea: [v] event action.
  • dt: document page title, basically the name of the event that you'll see later.
  • cm: medium of the campaing, in this case email.
  • ck: campaing keyword, in this case ck=MatchUpPadel%20Email.

But the are many other fields you can use and see at the Google's website measurament protocol parameter reference.

Crear Email

Besides, to help us create this link with the parameters we want, Google has the tool Hit Builder where we can build our own link with each parameter and we can validate the link at the end.

Ignacio Borrajo
Feb. 17th 2016, Ourense

Leave a comment

Comments

  • Miguel, 22.04.2016:

    Artículo buenísimo y super detallado!! Lo he probado con mi proyecto y funcionó a la primera.