1

I would like to track email opens with Google Analytics using the signature in the email. There are quite some articles on this (e.g. Tracking email opens in Google Analytics) however as I understand it, these would only provide a general open rate per campaign. E.g. if I send 100 emails, it would send me the % of emails that were opened.

What I would like to know, is what exact email has been opened. Let's say I send 4 emails, I would like to know which of these 4 emails was opened. Since all examples use a general GA campaign, this is not covered in these solutions (right?).

I guess in some way, it would have to pass a unique ID with the pixel upon adding the signature. Potentially through the Scripts API? Any ideas on how this could be done? I doesn't have to be through the signature, I just figured this would be easiest. If there are other ways of doing this when an email is created or sent, then this would also be very helpful.

EDIT: Requirement to the solution would be that I install or connect it once, and from there on it will add this unique ID automatically (or upon adding the signature).

EDIT 2: I came up with a potential solution, however I am not confident this is best practice. I could use the Google Apps Admin SDK to set a signature for a user, which includes a unique tracking code. As soon as an email with this tracking code is sent, I could update the signature again with a new tracking code. It's the best I've come up with so far. Maybe it sparks some other ideas...

EDIT 3: In response to the campaign suggestions: the idea is that this tracker should be easy to add when I send a normal email from GMail. Therefore solution like SendGrid are not suitable, cause I would habe to leave my normal email client for it.

Community
  • 1
  • 1
Vincent
  • 1,137
  • 18
  • 40

3 Answers3

1

I know this isn't the full answer, but your question mentioned Google Apps Scripts as a possible workaround. If you want to create a beacon that will register with Google Analytics, here is a function to do it. Just make sure you update the parameters at the top of the function.

/********************************
* Track in Google Analytics
********************************/
function getBeacon(campaignName) {
  var TAG_ID = 'UA-XXXXXXXX-X';
  var CAMPAIGN_SOURCE = 'email';
  var CAMPAIGN_MEDIUM = 'email';
  var CAMPAIGN_NAME = campaignName;
  var HOSTNAME = 'www.your-domain.com';
  var PAGE = '/email-campaign-page';
  var DOMAIN_LINK = 'http://'+HOSTNAME+PAGE;

  //Pulled from: http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
  var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, 
    function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);});

  var url = 'http://www.google-analytics.com/collect?';
  var payload = {
    'v':1,'tid':TAG_ID,'cid':uuid,    
    't':'pageview','cs':CAMPAIGN_SOURCE,'cm':CAMPAIGN_MEDIUM,'cn':CAMPAIGN_NAME,
    'dl':DOMAIN_LINK
  };
  var qs = '';
  for(var key in payload) {
    qs += key + '=' + encodeURIComponent(payload[key]) + '&';
  }
  url += qs.substring(0,qs.length-1);
  return url;
}

You can run that from a Google Script and it will return a url that when placed in an image tag, will register with Google Analytics.

function sendEmail() {
  var TO = ['user1@email.com','user2@email.com','user3@email.com'];
  for(var i in TO) {
    var toEmail = TO[i];
    var uniqueIdentifier = Utilities.base64EncodeWebSafe(toEmail);
    var trackingUrl = getBeacon(uniqueIdentifier);
    var htmlBody = '<html><head></head><body>';
    htmlBody += 'This is my email! Come to my <a href="http://www.example.com">site</a>!';
    htmlBody += '<img src="'+trackingUrl+'" style="display:none;"/>';
    htmlBody += '</body></html>';
    var options = { 
      htmlBody : htmlBody,
    };
    var subject = 'My Email Subject';
    MailApp.sendEmail(toEmail, subject, 'You should have an html email reader by now.', options);
  }
}

The one thing i would watch out for is that with Google Analytics, you should not be tracking things at the email address level (PII shouldn't be in GA). When you said you want to track 4 unique emails, i assumed you meant 4 batches of emails, each with their own id.

Thanks,
Russ

Russ Savage
  • 598
  • 4
  • 20
  • Thanks Russ. I actually did mean unique emails. I would have a unique ID in an email, which could of course be opened by more than one user (multiple recipients or if forwarded). What do you mean by saying that this wouldn't work in GA? – Vincent Mar 24 '15 at 06:27
  • As per [GA guidelines](https://support.google.com/analytics/answer/2795983?hl=en) i don't think it's allowed. That being said, if you wanted to make your "campaign identifiers" unique hashes of the email addresses they were sent to, i have updated my answer. And of course, you could just make the campaign identifiers the exact email address, but that is certainly against GA policy. – Russ Savage Mar 24 '15 at 06:37
  • Also, this method really isn't scalable, since you can only send [100 per day](https://developers.google.com/apps-script/guides/services/quotas#current_quotas). – Russ Savage Mar 24 '15 at 06:43
  • Right. But as long as I use a unique ID which is not an email address or other direct identifier I should be fine right? Please note that this is not for for bulk messages, but for tracking single messages during normal communication. The 100 messages limit should therefore not be an issue. Now to automatically set a unique identifier per tracked email, I am thinking of adding this in the signature, and changing the signature programmatically after each sent email to include a new unique ID. Do you think that works? If so, then that would be the solution... – Vincent Mar 24 '15 at 10:37
  • if that's the case, maybe you should update the code to just provide you with the image tag to include in your email. For example, i created this using google scripts and deploying it as a webapp: https://script.google.com/macros/s/AKfycbx36xekI0gbHEXcYGXjQ6T2K2BjVa3-CHMh-FhJv1YSUvpqJPHx/exec would that work? – Russ Savage Mar 24 '15 at 16:01
  • In terms of inclusion in the email: yes, that would work. My main question is how to programmatically update the unique ID, so that I don't have to think of this every time. My guess is that through the signature is the easiest / only way. Or I would have to be able to edit the template for new emails somehow... – Vincent Mar 24 '15 at 16:45
  • Hi Russ, I accredited the bounty already since it would else expire. Though to fully accept the answer I would need feedback on my latest comment. Thanks a lot for your help! – Vincent Mar 25 '15 at 12:29
  • The problem is that some mail clients request images before emails are opened. gmail, for example, [pulls the images before it gets to the user](http://arstechnica.com/information-technology/2013/12/gmail-blows-up-e-mail-marketing-by-caching-all-images-on-google-servers/) and before they open the email so if the person you are mailing is opening in gmail, you won't get the correct data. Even when i opened the email in a new window, or refreshed my gmail, it wasn't requesting the image again, so you won't truly have a count of opens. – Russ Savage Mar 25 '15 at 19:09
  • (continued) Long story short, I think you're much better off using something like [Tout](http://www1.toutapp.com/tout-tracking/). You can revoke the bounty if you want but if this is really important to you, it is probably worth investing some money in a real solution. – Russ Savage Mar 25 '15 at 19:10
  • Thanks Russ. Yes I am aware of this, but the caching by GMail shouldnt affect open tracking if implemented correctly (there are multiple articles on this since they changed it). I know most solutions on the market but have my reasons for wanting to make this myself. From your feedback I make that changing the unique ID in the signature would be an option, as long as I can make sure that I have a good tracking method in place. Would you agree? – Vincent Mar 26 '15 at 05:45
1

http://dyn.com/blog/tracking-email-opens-via-google-analytics/

Using the above technique you can apply a unique userID (non identifiable, obviously) to each user and then in your scenario where you send 4 different emails and want to know which was opened you could modify the following :

cs=newsletter   Campaign Source allows segmentation of campaign types
cm=email    Campaign Medium could segment social vs. email, etc.
cn=Campaign_Name    Campaign Name identifies the campaign to you

so cn=emailOne / emailTwo / emailThree / emailFour etc.

On a side note, if I were being sent 4 emails in quick succession the only reason I would open one would be to find the unsubscribe link.

Chris Traverse
  • 113
  • 1
  • 10
  • Thanks Chris. Yes this is what I have in mind. Note that the 4 emails would typically have different recipients, so no worries on unsubscribing ;) – Vincent Apr 14 '15 at 08:35
0

Yes, you can do that, you can reinvent the wheel and hack Google Analytics to track something it was not designed to do. Spend a lot of time trying to integrate that into your email sending and making sure that it outputs a gif into each email with a unique identifier and sending that to GA using the Measurement Protocol. Then all you have to do is just pull this data from GA using their API and reconcile the unique identifiers back to the emails on your end and there you go.

OR You can not reinvent the wheel. Use one of the several tools available for email marketing that have these features baked in.

SendGrid and MailChimp are good options to start looking at.

Eduardo
  • 22,574
  • 11
  • 76
  • 94
  • Yes I've looked into these solutions, however they only provide statistics on a campaign level. What I need, are statistics per email, meaning every email should have a unique tracker. In addition, it has to work on emails that are being sent through GMail. As far as I understand, services like SendGrid and MailChimp are no option for that. – Vincent Mar 20 '15 at 21:15
  • Just to be clear: the idea is to offer this feature as part of a package of service that we offer users. So I don't need a fix for sending my emails, but a way to do this for any GMail account. – Vincent Mar 20 '15 at 21:19
  • Ok I also added the steps you would need to do to track that in GA – Eduardo Mar 21 '15 at 00:40
  • Thanks Eduardo. I get how this would work, but how would an email get a unique identifier? If I e.g. add the code in my signature and want to get open information per email, I would have to change one of the utm parameters every time I send an email to make sure it is unique, right? What I am looking for, is a way to do this automatically. Please correct me if I'm wrong. – Vincent Mar 21 '15 at 05:50
  • You can get per email real time events from SendGrid via their Event Webhook, this would allow you to do stats on a per email basis. More info here: https://sendgrid.com/docs/API_Reference/Webhooks/event.html – Martyn Davies Mar 21 '15 at 19:14