in reply to Create email tracking image

Can you suggest a more elegant solution?

1. Don't. A sane mail client won't load remote images, so tracking won't work.

2. Don't generate the same constant image over and over again. Use any tool you like to create the transparent pixel image as GIF or PNG once. I used Google ("transparent pixel gif") and found this page. It lists the resulting binaries conveniently as base64 strings. For a transparent pixel in GIF format, it is R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==, in PNG, it is iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQYV2NgYAAAAAMAAWgmWQ0AAAAASUVORK5CYII=. Now you can use MIME::Base64 or similar to convert that to a binary:

use MIME::Base64 qw( decode_base64 ); # ... print "Content-type: image/gif\n\n"; binmode STDOUT; print decode_base64('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAA +AICRAEAOw==');

Of course, you could even get rid of MIME::Base64 by recoding that to hex, and use pack to write the binary without any extra modules:

>perl -MMIME::Base64 -e 'print decode_base64("R0lGODlhAQABAIAAAP///wAA +ACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")' > pixel.gif >perl -MMIME::Base64 -e 'print unpack("H*",decode_base64("R0lGODlhAQAB +AIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="))' 47494638396101000100800000ffffff00000021f90401000000002c00000000010001 +000002024401003b >perl -e 'print pack("H*","47494638396101000100800000ffffff00000021f90 +401000000002c00000000010001000002024401003b")' > pixel2.gif >md5sum pixel.gif pixel2.gif 325472601571f31e1bf00674c368d335 pixel.gif 325472601571f31e1bf00674c368d335 pixel2.gif >
Like this:
print "Content-type: image/gif\n\n"; binmode STDOUT; print pack('H*','47494638396101000100800000ffffff00000021f904010000000 +02c00000000010001000002024401003b');

You could even get rid of pack:

>perl -MMIME::Base64 -MData::Dumper -e '$x=decode_base64("R0lGODlhAQAB +AIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="); $Data::Dumper::Us +eqq=1; print Dumper($x);' $VAR1 = "GIF89a\1\0\1\0\200\0\0\377\377\377\0\0\0!\371\4\1\0\0\0\0,\0\ +0\0\0\1\0\1\0\0\2\2D\1\0;"; >

Et voilą:

print "Content-type: image/gif\n\n"; binmode STDOUT; print "GIF89a\1\0\1\0\200\0\0\377\377\377\0\0\0!\371\4\1\0\0\0\0,\0\0\ +0\0\1\0\1\0\0\2\2D\1\0;";

(Note: That assumes an ASCII-based system. EBCDIC probably won't work with that constant.)

And there is more: You can omit binmode on Unix, as Unix is 8-bit-clean. On DOS-based systems (DOS, OS/2, Windows), binmode prevents converting \n = \012 = 0x0A to \r\n = \015\012 = 0x0D, 0x0A. THIS GIF luckily contains no \n = 0x0A, so it does not matter if \n is converted or not. So for this constant, you can omit binmode also on DOS, OS/2, Windows:

print "Content-type: image/gif\n\nGIF89a\1\0\1\0\200\0\0\377\377\377\0 +\0\0!\371\4\1\0\0\0\0,\0\0\0\0\1\0\1\0\0\2\2D\1\0;";

Yipp, a single line of code works on Unix, DOS, OS/2, and Windows.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^2: Create email tracking image
by Bod (Parson) on Mar 21, 2023 at 22:34 UTC
    Don't. A sane mail client won't load remote images, so tracking won't work

    There is the difference between a programmer and a marketer!

    We get between 30% and 50% reported open rate from most emails on their first send1. So, at least 30% of our email lists have images turned on. Whilst it may seem an increase in privacy to block remote images, it actually means that the end user receives far less relevant content. A typical email campaign of ours splits the audience into four groups.

    1. Those who have not opened the email
    2. Those who have opened it but not acted on it
    3. Those who have partially acted (perhaps started watching a video)
    4. Those fully engaged (e.g. watch all the video)
    Each group will get different content and maybe that will be tailored depending on what they have engaged with in the past.

    Our email campaigns are quite sophisticated with some campaigns having over 100 different emails and variations for different people at different times. Most of the content is educational material designed to help our prospects, build our credibility and remind them that we exist. This level of sophistication and relevance would be limited without tracking images enabled as we would be relying solely on clicks and other triggers.

    1 Typically the first email in a campaign will be resent up to 5 times with a different subject to people who have not yet opened it

    2. Don't generate the same constant image over and over again.

    Yeah - that was exactly the point of the question...

    And there is more: You can omit binmode on Unix, as Unix is 8-bit-clean.

    Thank you kindly

    That is exactly the kind of solution I was looking for and having a mental block over!

      If I was the target I would prefer a newsletter to contain weblinks for further reading after an initial title/introduction in the email body. This way you would be getting multi-dimensional data on each genuinely interested user. Weather they opened it or not it does not matter. Have they expressed interest in visiting the stories/products? That's what matters.Then keep changing the stories to see if you get any heartbeat. Deleting the newsletter unread, straight from the queue perhaps it's because they have the impression it is of no interest whatsoever. In which case I find it easier to unsubscribe and get rid with this hassle. Why would I delete email unread?: Tacky titles, past experience as being useless or with aggressive marketing, marketing lingo, excessive company logos, headers, tons of legal footer, idiots.