• Resolved onnosolin

    (@onnosolin)


    I’m having trouble getting Google Optimize working together with AMP. My setup:

    • WordPress 5.4.1
    • Child theme of Twenty Twenty
    • AMP plugin
    • “amp-experiments script version rollback” plugin
    • MonsterInsights Pro plugin, with Google Optimize and Google AMP Addons

    I’ve set up Google Analytics (tracking fine in both Google Analytics itself and in MonsterInsights), and Google Optimize – which is running fine as long as I deactivate AMP.

    I have also inserted the container code in the Optimize Addon for MonsterInsights Pro.

    The problem is that I can’t get Google Optimize to work with AMP enabled. The live debugger for the page where I’m running the experiment (https://www.onlinecoursewizards.com/page-a/) says:

    “The Google Optimize snippet for the container with ID GTM-KD4XQRK is not correctly installed on this page. To preview experiences or debug the container, make sure the Google Optimize snippet is installed on any pages you want to test.”

    I have tried to follow this guide: https://developers.google.com/optimize/devguides/amp-experiments. The first instruction there is to include the <amp-experiment> and <amp-analytics> components.

    But if I try to add <amp-experiment> tag to my template’s header.php file as follows:

    <script async custom-element=”amp-experiment”
    src=”https://cdn.ampproject.org/v0/amp-experiment-0.1.js”></script>

    – then the tag is removed from the source code upon rendering the page.

    I was wondering if you’d have any tips to get Google Optimize to play nicely with AMP?

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

Viewing 8 replies - 1 through 8 (of 8 total)
  • @onnosolin thanks for your topic. We’re currently looking into this with the team, but a question in the meantime:

    Would you happen to know if the Monster Insights Optimize Add-on is AMP-compatible?

    It seems like their AMP add-on states compatibility with our plugin, but it would be great to know if the other is too.

    Thread Starter onnosolin

    (@onnosolin)

    @reneesoffice thanks for your reply.

    Yes, MonsterInsights do claim that their Optimize plugin is compatible:

    “MonsterInsights is the only Analytics WordPress plugin that lets you integrate with Google AMP that also supports Google Optimize.”

    See also: https://www.monsterinsights.com/how-to-add-google-analytics-to-amp-pages-on-wordpress/.

    @onnosolin thanks for the info!

    While I don’t have the Monster Insights Pro plugin and the add-ons to check if there is a particular configuration required (perhaps checking with their support would be helpful too), when following the guide for the manual configuration, you actually don’t have to add the amp-experiment component script to the head. The AMP plugin will add it automatically once it detects the corresponding component in the source code.

    Using the mini-plugin you’ve referenced ensures the stable version of the amp-experiment component script is loaded (fix in the core plugin planned here).

    You should be able to proceed with the guide by adding the required components to the body.

    Site Kit also has an Optimize implementation available with support for amp-experiment, which is an option to explore.

    Thread Starter onnosolin

    (@onnosolin)

    @reneesoffice Would you have any tips for how to test for the automatic inclusion of the script? I’ve tried this in the Google Chrome console for the web page (https://www.onlinecoursewizards.com/page-a/) but it does not seem to yield any results:
    ”$( “[src*=’https://cdn.ampproject.org/v0/amp-experiment-0.1.js’%5D&#8221; );”
    – Result: ”null”

    Thread Starter onnosolin

    (@onnosolin)

    Sorry, applied wrong markup. Here goes again:
    $( "[src*='https://cdn.ampproject.org/v0/amp-experiment-0.1.js']" );
    results in null

    @onnosolin I see it directly when inspecting your site’s source code (right click > View Page Source in Chrome) in the browser: https://jmp.sh/EuCYkSh

    I did a search for “amp-experiment” to find all instances.

    Thread Starter onnosolin

    (@onnosolin)

    Yeah, it seems once I included <amp-experiment> and <amp-analytics> code, the component script was also included automatically.

    However, I still can’t get it working. I have this code:

    <amp-experiment>
      <script type="application/json">
        {
          "RedirectTestExperiment": {
            "sticky": true,
            "variants": {
              "0": 50,
              "1": 50          
            }
          }
        }
      </script>
    </amp-experiment>
    
    <amp-analytics id="analytics1" type="googleanalytics">
    <script type="application/json">
    {
      "vars": {
        "account": "UA-28755973-8"
      },
      "requests": {
         "experiment": "${pageview}&xid=${xid}&xvar=${xvar}"
      },
      "triggers": {
        "trackPageview": {
          "on": "visible",
          "request": "experiment",
           "vars": {
             "xid": "CdjgjGF0Q6SJY1l-6e0VyQ",
             "xvar": "VARIANT(RedirectTestExperiment)"
           }
        }
      }
    }
    </script>
    </amp-analytics>

    But I keep running into the same error message produced by Google Optimize’s live debugger:

    “The Google Optimize snippet for the container with ID GTM-KD4XQRK is not correctly installed on this page. To preview experiences or debug the container, make sure the Google Optimize snippet is installed on any pages you want to test.”

    @onnosolin thanks for your reply. This might be a question for the Optimize forums. I’m not completely sure if it is checking for the amp-experiment implementation.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Getting Google Optimize plugin to work with AMP’ is closed to new replies.