Forums

Google Analytics for WordPress
Anchor Link Changed - Includes Full URL (5 posts)

  1. php4ever
    Member
    Posted 10 months ago #

    Hey Joost, I found a small issue in the plugin that others might experience too regarding Anchor Links and the pound # sign.

    While checking my site recently I discovered that my site was hammered to death by 404 errors all of which were ANCHOR Link related. After viewing source view of the HTML I discovered that literally every single anchor link in my site had full URL's added in front of the anchor making all of them broke.

    For instance;
    <a href="#testing">testing</a> would become
    <a href="http://domain.com/name-of-article/#testing">testing</a>

    I think the fix for this is relatively easy and wanted to give you a heads up.

    GREAT Plugin none the less!
    Nice work.... :-)

    J

  2. petethechop
    Member
    Posted 10 months ago #

    I've experienced the same issue. I would love to see this resolved. It breaks JQuery scripts that rely on the #id for targeting. Meanwhile I'm using a different GA plugin.

  3. Michael Arestad
    Member
    Posted 7 months ago #

    I ran into the same issue and solved it this morning. Try adding single quotes around the href content inside the double quotes like this:

    <a href="'#testing'">testing</a>

  4. petethechop
    Member
    Posted 7 months ago #

    That's a decent interim fix, Michael. However, most of the time I run into this issue the hashed link is being generated by some JQuery or WordPress plugin and isn't easily manipulated like that. For example, I'm trying to use Easy FancyBox.

  5. Attila Fulop
    Member
    Posted 1 month ago #

    The '' trick didn't work for me, however the following trick did it:
    1.) I padded the links with a space:
    <a class="fancybox" href=" #testing ">testing</a>
    This prevents the GA plugin to recognize and change it

    2.) I added a piece of javascript after all the elements

    <script type="text/javascript">
       jQuery('a.fancybox').each(function() {
          jQuery(this).attr('href', jQuery.trim(jQuery(this).attr('href')));
       });
    </script>

    This removes the space and now the links work as expected.

    Please note that it only works until GA plugin developers will trim the links (that'd make sense).

Reply

You must log in to post.

About this Plugin

About this Topic