How to know the number of recipient have open the email through google analytic?

Go To


I am using swiftmailer , a library for sending mail in php. The problem is , I have already register a google analytic account.

How can I use this tool to check how many person have opened the email ?

Thank you.


Ok, trackcode is in js , sure would not work. Images have some chance if the user allow it.

To be precise, what should i include in the image.php,

and is that mean i go to google analytics webpage and track the ../image.php?id=xxx then i can get result?

should i add the code in php?

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-29940706-1']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

2012-04-04 03:45
by Leo Chan


You can't do it with 100% reliably. You can embed a webbug in the mail, but most mail clients automatically block any 3rd-party content from being loaded automatically. If the user doesn't say "ok, please load the images", then you'll never see the webbug hit come in.

You can request a return receipt on the email, but most mail clients will ignore that, or default to not sending one, or the user will decline to confirm receipt.

if you want to confirm that people have read the email, then your best bet is to NOT mail the content you want tracked, and simply send a LINK to that content:

"please click here to read an important announcement"

and the link would include a unique identifier tied to the particular email address the message was sent to. If you get a hit on that address, someone read the message and clicked the link, and the embedded tracking code will tell you who did so.

2012-04-04 03:48
by Marc B
If you aren't aware of it, a 'web bug' is a small (typically a 1x1 pixel transparent GIF) image loaded by the user's mail client/browser that provides those that host the bug information about the system that accessed the content being tracked. Also, the default way Google Analytics gathers information is via inclusion of javascript stored in GA's servers, but since the prevalence of email worms in the late 90's and early 00's, no email client will run scripts by default anymore - Ariel 2012-04-04 03:50
That means only two way: insert a image, track that . or provide my newsletter in the lin - Leo Chan 2012-04-04 04:05
Exactly. images are utterly unreliable and almost guaranteed to not work. And personally, if I get an email telling me to click some big long ugly link with an obvious tracking code embedded in it, that email goes straight to trash/spam - Marc B 2012-04-04 04:07
If i would like to implement in the first way, i have to create many 1 x 1 picture? Say, if i have 10 campagin , i need to have 10 picture - Leo Chan 2012-04-04 04:07
No. only one image. it can be <img src="">, but remember, it's pretty much guaranteed to NOT work. Mail clients don't load remote images unless explicitly authorized by the user - Marc B 2012-04-04 04:09
Thanks . Have you ever heard about, it is a online mail service , but why they can get the open rate without using link - Leo Chan 2012-04-04 04:11
doesn't matter which service or mail library you use. Any guarantees they can give you of how trackable their emails are will turn out to be heavily exagerrated at best, and most likely flat-out outright cow droppings the rest of the time - Marc B 2012-04-04 04:13
I see , that means they are using the images method as well? No any other magical way to implement this - Leo Chan 2012-04-04 04:15
No idea what they use, but there's no "magical methods". It's all just SMTP email in the, and you're limited to what the user's mail client can do. These days, there are NO mail clients that auto-load remote content (e.g. web bugs), and very few of them will honor return receipt requests. Tracking by email is EXTREMELY unreliable. Anyone who promises otherwise is flat out lying - Marc B 2012-04-04 04:17
Thanks. Although unreliable, i would like to implement the image method as the user may want to directly mail the content. Last question, So , the way to do this is have a php (but it should be jpg,gif?) Then how can i add the google trackcode to track the result? Thank - Leo Chan 2012-04-04 04:23
You can't. Google tracking works off javascript loaded into a full html web page. You can embed the GA tracking stuff into your email, but the same restrictions apply to remote JS as does to remote images - unlikely to be loaded, highly unlikely to be executed - Marc B 2012-04-04 04:25
Ok, trackcode is in js , sure would not work. Images have some chance if the user allow it. To be precise, what should i include in the image.php, and is that mean i go to google analytics webpage and track the ../image.php?id=xxx then i can get result - Leo Chan 2012-04-04 04:29


To get full Google Analytics integration for your newsletters, take a look at this official blog post addressing this subject:

2012-04-04 05:54
by Repox
thats just clicks, it doesn't include view - Kevin 2012-08-26 20:00