WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. php4ever
    Member
    Posted 3 years 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 3 years 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 2 years 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 2 years 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 2 years 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).

  6. shahar
    Member
    Posted 2 years ago #

    Thanks for posting the bug and fixes

  7. loudirian
    Member
    Posted 2 years ago #

    I found the same problem today. I'm using a plugin that dynamically creats links and those links don't work when using the Google analytics for WordPress plugin.
    Deactivating the Google analytics for WordPress plugin solves the problem.

    Unfortunately I cannot use the workarounds given in this thread as I don't want to alter the code from the plugins (in case of future updates etc.)

    I'm using the latest version from the Google analytics for WordPress plugin.

    Is this going to be resolved in the near future?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic