• Workaround and fix for Google Analytics by Yoast internal links becoming broken outbound-article-int

    For a while now I’ve been seeing strange links appearing on my blog pages. They first appeared after upgrading Google Analytics by Yoast from version 4.3.5 to version 5. I had hoped that the problem would have been fixed by now. But I’m still getting it with version 5.1.2.

    Problem Summary

    Expected result

    The continue reading link should appear as Continue reading →.

    Actual result

    The link is displayed incorrectly as →’]);” class=”more-link”>Continue reading →

    Workaround

    The problem occurs after upgrading to Google Analytics v5.0.x

    It can be fixed by taking the following actions:

    • From the Plugins page select the Google Analytics by Yoast Settings link
    • Select the Advanced tab
    • Type a space into the Set path for internal links to track as outbound links: input field
    • Click on the Save changes button.

    Explanation

    The problem is due to the incorrect addition of some Google Analytics tracking of an “outbound-article-int”.

    The original HTML for the Continue reading link

    <a href="http://oik-plugins.uk/oik-plugins/wordpress-core/#more-15739"
     class="more-link">
      Continue reading <span class="meta-nav">&rarr;</span>
    </a>

    has been modified by Yoast’s Google Analytics plugin to include some tracking of an “outbound-article-int” event.

    <a href="http://oik-plugins.uk/oik-plugins/wordpress-core/#more-15739"
     onclick="_gaq.push(&#91;'_trackEvent', 'outbound-article-int', 'http://oik-plugins.uk/oik-plugins/wordpress-core/#more-15739',
     'Continue reading <span class="meta-nav">
    &rarr;</span>']);"
       
      class="more-link">
      Continue reading
      <span class="meta-nav">&rarr;</span>
      </a>

    Additionally the embedded span around the right arrow has caused a parsing formatting error.

    Proposed fix

    There are two parts to the fix:

    1. Prevent the code from creating the outbound-article-int link
    2. Ensure that the Continue reading link text is correctly escaped; we certainly don’t want the double quotes.

    Solution to prevent the code from creating the outbound-article-int

    A quick fix is to check on the value of $out before performing the strpos() in Yoast_GA_Frontend::get_target()

    $out_links = explode( ',', $this->options['track_internal_as_outbound'] );
    if ( count( $out_links ) >= 1 ) {
      foreach ( $out_links as $out ) {
        if ( ! empty( $original_url ) && ! empty( $domain['domain'] ) ) {
          if ( $out && strpos( $original_url, $domain['domain'] . $out ) !== false ) {
            $type = 'internal-as-outbound';
          }
        }
      }
    }

    A better fix would also move the !empty() tests out of the loop, before the explode().

    Note:Initially I couldn’t reproduce the problem in my development environment since my host name is “qw”… so the $domain[‘domain’] is empty. I hacked the code to be able to create the problem.

    Solution for the Continue reading link

    Further investigation indicates that this problem is associated with themes generated using Artisteer. The Google Analytics for WordPress code correctly attempts to escape the link text

    esc_attr( strip_tags( $link['link_text'] );

    but this doesn’t achieve anything when the link text is %%theme_more%% which gets replaced later on in the processing.

    It would appear that the fix would need to be applied to the theme. The $more_tag is defined in theme_get_excerpt() in functions.php. This uses double quotes in the span around the right arrow. Change these to escaped single quotes and the problem goes away.

    function theme_get_excerpt($args = array()) {
            global $post;
            $more_tag = theme_get_array_value($args, 'more_tag', __('Continue reading <span class=\'meta-nav\'>&rarr;</span>', THEME_NS));

    If the first fix has been applied then this change is only necessary if “outbound-article-int” processing is required and it’s a read more link.

    See also

    It turns out I was not the only person with these problems.


    ,

    Published:

    Last updated:

    November 19, 2014

Categories

Tide times from tidetimes.co.uk

Tide Times & Heights for Langstone Harbour on
Monday, 29 November 2021
High Tide:06:29 ( 4.20m )
Low Tide:12:19 ( 1.80m )
High Tide:18:54 ( 4.10m )

Tide times from tidetimes.org.uk

Tide Times & Heights for Northney on
29th November 2021
06:48 High Tide ( 4m )
12:15 Low Tide ( 1.67m )
19:11 High Tide ( 3.92m )