• Resolved samftm

    (@samftm)


    Hi there, I have an issue regarding AMP traffic in Google Analytics.

    In the AMP plugin settings, I’ve enabled the option “Redirect mobile visitors to AMP”. Now, every time someone from Google’s organic search clicks on my website, the acquisition will be registered as “Direct” traffic instead of “Organic Search” in Google Analytics. I’d like this to be Organic Search instead of Direct.

    I’m using the Transitional mode instead of the Standard mode, since Standard mode breaks my site. Currently, the url changes from example.com/post/ to example.com/post/?amp in mobile.

    I’m using the Site Kit plugin to add the snippet and the View is set to “All Web Site Data”.

    So, is there a way to make all the mobile Organic clicks redirect to the AMP version of my site, while still registering as Organic instead of Direct?

    Thank you for the AMP plugin, a really great plugin for those who are not programmers!

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 17 total)
  • Apologies for the delay in responding. When somebody accesses your site from a mobile search most likely they’ll typically arrive directly on the AMP version of your site, with search engines determining the most suitable version (example). This traffic should already be treated as organic.

    If a visitor does happen to arrive on the canonical (non AMP) version of your site on mobile at this stage they’ll be redirected, with the source no longer “organic”. Please allow me some time to check whether a server side redirect should resolve this.

    Thread Starter samftm

    (@samftm)

    Hi @jamesosborne

    Thank you for your reply, it makes sense. It looks like some AMP pages are not yet cached by Google in the search results, showing my normal website instead of the cached AMP version (like the image you’ve posted). So this in turn results in a redirect to /?amp, which then registers as a direct view. I understand now.

    I’ve just clicked on an existing AMP page in the search results and the click registered as organic, which is exactly what I wanted.

    Once the urls are reclawed, I assume that all the AMP enabled posts will show up as direct AMP pages in the search results. So I don’t think it’s really necessary to make a server side redirect, since this probably will happen soon anyway. Or am I wrong?

    Yes, you are correct. Once the Search Engines determine there is an AMP version of your content it will be that version served to users, resulting in a better representation of your organic traffic.

    I noticed also you’re using Generate Press, did you apply the themes AMP add on to ensure your navigation menu works in AMP?

    Thread Starter samftm

    (@samftm)

    Yes, I did install and activate the GP AMP plugin. Thank you for that suggestion, and support regarding AMP and analytics. I’ll close this support topic.

    Thanks again @jamesosborne ??

    No problem at all, be sure to get in touch should you have any further AMP related queries. If you have a moment free also share your thoughts as a user of the AMP plugin.

    Heya, I’m having a similar issue with our site. When redirect is enabled, mobile users lose their referrer data. I tested this using chrome://inspect/#devices and have since turned redirects off.
    But users who come from Google Discovery, which chooses the amp version to serve regardless of redirects, also seems to lose it’s referer.

    Yes I am also still experiencing a much larger than expected portion of traffic labelled as direct in GA.

    Much of it is /?AMP=1 traffic. Say about 50% of the direct traffic is amp
    But some AMP traffic is recording correctly as organic

    I also have redirect enabled.

    Q: will moving to Google Analytics 4 tags make any difference?

    https://the5krunner.com (AMP 2.0.9)

    @the5krunner @obscurenamedigit You may need to apply a server side redirect to attribute organic traffic. You’ll find one example of server side redirect below which you can try:

    add_action(
    'wp',
    function() {
    add_action( 'amp_mobile_client_side_redirection', '__return_false' );
    add_filter( 'amp_pre_is_mobile', '__return_true' );
    
    if ( ! isset( $_GET['noamp'] ) && wp_is_mobile() && function_exists( 'is_amp_endpoint' ) && ! is_amp_endpoint() && function_exists( 'amp_is_available' ) && amp_is_available() ) {
    wp_safe_redirect( esc_url( add_query_arg( 'amp', '1', get_permalink() ) ), 302 );
    }
    }
    ); 

    You can turn off mobile redirection from the AMP plugin add the script above to your themes functions.php file or preferably a custom plugin to ensure it doesn’t get overwritten.

    Q: will moving to Google Analytics 4 tags make any difference?

    Unfortunately Google Analytics 4 isn’t fully supported in AMP URLs just yet although this is a great question. You can keep track on it’s status here. I’ll keep tabs on this also to see what changes and updates are applied to GA4 with AMP once shipped.

    hi James

    sadly, that add_action code errors out in functions.php

    this was suggested. doesn’t error out but i don’t thin kit redirect either!

    add_filter( ‘amp_mobile_client_side_redirection’, ‘__return_false’ );

    Plugin Author Weston Ruter

    (@westonruter)

    @the5krunner This is the only code you should need to disable client-side redirects in favor of server-side redirection, which will retain the original referrer:

    add_filter( 'amp_mobile_client_side_redirection', '__return_false' );

    This can be put in your theme’s functions.php, unless you’re using Reader mode in which case it should go in a custom plugin. Nevertheless, server-side redirection may conflict with page caching you may have on your site. So that will need to be checked.

    In any case, we are currently investigating a way to allow the original referrer to be passed along even when client-side redirection is being done: https://github.com/ampproject/amp-wp/pull/5776

    • This reply was modified 3 years, 10 months ago by Weston Ruter.
    Plugin Author Weston Ruter

    (@westonruter)

    Please note that to test the server-side redirection you should do so when logged-out of WordPress or in an incognito window. When you’re logged-in the client-side redirection is always enabled in order to properly integrate with the Customizer and paired browsing.

    the server-side redirect code above from @jamesosborne will not save. it is invalid code

    @westonruter, yes your code to disable client-side redirection is valid code that I have implemented but i don’t see a big change in the DIRECT traffic on analytics.

    thank you for any further assistance

    Plugin Author Weston Ruter

    (@westonruter)

    @the5krunner I’m still seeing the JavaScript-based redirection being done. Specifically, your non-AMP page at https://fitium.nl has this script at the top:

    <script>!function(e){var r={};function n(t){if(r[t])return r[t].exports;var o=r[t]={i:t,l:!1,exports:{}};return e[t].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=r,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,r){if(1&r&&(e=n(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(n.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)n.d(t,o,function(r){return e[r]}.bind(null,o));return t},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},n.p="",n(n.s=0)}([function(e,r){!function(e){var r=e.ampUrl,n=e.isCustomizePreview,t=e.isAmpDevMode,o=e.noampQueryVarName,a=e.noampQueryVarValue,i=e.disabledStorageKey,u=e.mobileUserAgents,s=e.regexRegex;if("undefined"!=typeof sessionStorage){var f=new RegExp(s);if(u.some((function(e){var r=e.match(f);if(r&&new RegExp(r[1],r[2]).test(navigator.userAgent))return!0;return navigator.userAgent.includes(e)}))){document.addEventListener("DOMContentLoaded",(function(){var e=document.getElementById("amp-mobile-version-switcher");if(e){e.hidden=!1;var r=e.querySelector("a[href]");r&&r.addEventListener("click",(function(){sessionStorage.removeItem(i)}))}}));var c=t&&["paired-browsing-non-amp","paired-browsing-amp"].includes(window.name);if(!(sessionStorage.getItem(i)||n||c)){var d=new URL(location.href),l=new URL(r);l.hash=d.hash,d.searchParams.has(o)&&a===d.searchParams.get(o)?sessionStorage.setItem(i,"1"):l.href!==d.href&&(window.stop(),location.replace(l.href))}}}}({"ampUrl":"https:\/\/fitium.nl\/?amp=1","noampQueryVarName":"noamp","noampQueryVarValue":"mobile","disabledStorageKey":"amp_mobile_redirect_disabled","mobileUserAgents":["Mobile","Android","Silk\/","Kindle","BlackBerry","Opera Mini","Opera Mobi"],"regexRegex":"^\\/((?:.|\n)+)\\/([i]*)$","isCustomizePreview":false,"isAmpDevMode":false})}]);</script>

    This script should not be added (for unauthenticated users) when this code is present:

    add_filter( 'amp_mobile_client_side_redirection', '__return_false' );

    I tried adding it to a test site of mine, and when I accessed the site in an incognito window, the script is indeed not added to the page. When I access the page in mobile, I am redirected to the AMP version via HTTP redirect as expected, instead of a JS-based redirect.

    hi
    thank you
    however !!
    my site is https://the5krunner.com . I have no affiliation with fitium.nl

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Google Analytics – AMP Direct View’ is closed to new replies.