Support » Plugins and Hacks » Tracking mailto links

Tracking mailto links

  • Hi Joost

    First of all thanks for a fantastic plugin, I use it on all sites I run, it makes life so much easier.

    I have found one thing, while working with a client. Your plugin doesn’t track mailto links. I believe you added that in 4.0.2, however the anchor pattern you currently use, does not catch them. I made a small example where I filter both a normal link and a mailto link:

    $text = '<a class="footerlink" href="mailto:example@example.com">example@example.com</a>';
    $text2 = '<a id="testid" class="testclass" href="http://www.test.dk/events-2/">» See all events</a>';
    static $anchorPattern = '/<a (.*?)href=[\'\"](.*?)\/\/([^\'\"]+?)[\'\"](.*?)>(.*?)<\/a>/i';
    preg_replace_callback( $anchorPattern, 'ga_parse_article_link', $text );
    preg_replace_callback( $anchorPattern, 'ga_parse_article_link', $text2 );
    function ga_parse_article_link( $matches ) {
                echo '<pre>';
                echo '</pre>';

    Furthermore this piece of code

    if ( strpos( $matches[2], "http" ) !== 0 ) {
        $target = false;
    } else if ( ( strpos( $matches[2], "mailto" ) === 0 ) ) {
       $target = 'email';
    } else {
        $target = GA_Filter::ga_get_domain( $matches[3] );

    Will never land us in the second option I believe.

    I think that an anchorpattern like

    static $anchorPattern = '/<a (.*?)href=[\'\"](.*?):\/?\/?([^\'\"]+?)[\'\"](.*?)>(.*?)<\/a>/i';

    Will find the mailto links as well, but I am uncertain of the implications in other parts of the code.

    I hope this is enough to make the issue clear, and if not just ask and I will try to explain a little more.



Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Tracking mailto links’ is closed to new replies.