/ Published in: PHP
This code can be used to add Google Analytics tracking tags to all links back to your site in email messages that you send. You can then track the referrals back to your site from those emails. See http://www.google.com/support/analytics/bin/answer.py?answer=55578&hl=en for a tool to help you build the tags.
Expand |
Embed | Plain Text
$email_body ="<a href='http://www.mysite.com/specials/?q=daily'>Args already present</a><br/> <a href='http://www.mysite.com/specials/'>No args already present</a><br/> <a href='http://www.mysite.com/'>Just a domain</a><br/> <a href = 'http://www.mysite.com'>Just a domain with no trailing slash</a><br/> <a href='https://www.mysite.com/specials/?q=daily'>https version</a><br/> "; '@href\s?=\s?(\'|")(https?://www.mysite.com(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)(\\1)@', '$matches', '$ga_tags = "utm_source=mysite&utm_medium=email&utm_term=spam&utm_content=lotsofit&utm_campaign=lotsofspam"; return $matches[6] ? "href=".$matches[1].$matches[2]."&".$ga_tags.$matches[1] : "href=".$matches[1].$matches[2]."?".$ga_tags.$matches[1];' ), $email_body ); print $email_body;
You need to login to post a comment.
