0

I'm building a module related to transactional emails, and one of the things that it does is add click tracking to transactional emails.

The way that it currently is doing that is by overloading the email template model (fully compatible with SMTP Pro), parsing links, and rewriting them to a controller of mine:

http://sitename.com/module/redirect/index/?link=http%3A%2F%2Fsitename.com/originallink/

I was thinking that perhaps a better approach would be to append query string variables to the original link:

http://sitename.com/originallink/?clicktrack=1&...

The nice thing about this is that it doesn't introduce a new dependency on my module. So that if for some reason the module needed to be disabled, it could be done without emails that had already been sent out now having broken links in them.

I would need to add a controller_action_predispatch observer to check for the existence of the query string variables and perform the click tracking.

But there may be a couple of downsides:

  • Performance overhead - Not too concerned about this one - it takes under 10ms to perform a check in PHP for the query string variables
  • FPC / Varnish - this one I'm a bit more concerned about - if the page is already cached by the time the user hits it, then the predispatch may not even run. The query string variables will be unique to the customer and the email they clicked on, so the URL itself will be reasonably unique, but if Varnish matches on the URL route and doesn't even care about the query string, then it will still get skipped.
  • If you add utm_campaign, utm_source, utm_medium vars to your email campaigns, they will track in Google Analytics as a new channel. – philwinkle May 23 '13 at 13:41
  • Ya I've played around a lot with the idea of building on top of GA, but I'm still leaning against it. I want to be able to have pretty tight control over the analytics - IP address and exact timestamps for each click and open, and to be able to query orders against that data in the Magento backend. Don't want to reinvent the wheel but I really don't need much in the way of powerful analytics, and GA tracking can actually be added overtop of my open/click tracking. – kalenjordan May 23 '13 at 14:35
  • 1
    Be careful with open redirects in this context. owasp.org/index.php/Open_redirect – Fabian Blechschmidt May 23 '13 at 17:03
  • Sha1 HMAC URL signatures FTW! ;) – davidalger May 27 '13 at 23:54
1

Use the google url builder get a good campaign url: https://support.google.com/analytics/answer/1033867?hl=en

It will take your base url and create a tracking url based on your info that you add and presents a link like: http://www.savethemage.com/?utm_source=Newsletter&utm_medium=Email&utm_content=Logo&utm_campaign=Order+Confirmation

Then take the part starting with ?: ?utm_source=Newsletter&utm_medium=Email&utm_content=Logo&utm_campaign=Order+Confirmation

and add it to the transaction email template for each link you want to track. Make sure you change the utm_content= to something unique for each link.

Then analytics will track all of those clicks.

| improve this answer | |
  • This was already suggested and the OP declined it. – philwinkle May 28 '13 at 1:59
  • This is exactly what I'm looking for. Especially the part about tracking individual link clicks with utm_content. Is there any way to track opens using utm variables? – Ted Apr 10 '15 at 22:05
1

Decided to implement my own controller for click-tracking. Not quite as a clean in terms of dependencies, but one way to avoid 404's after having disabled the module would be simply to setup a redirect from that route to the home page.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.