3

I've implemented a small experiment on an AMP site following this tutorial: https://developers.google.com/optimize/devguides/amp-experiments

Here's what I've done:

1. amp-analytics and amp-experiment components

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

2. Code for the experiment

<amp-experiment>
  <script type="application/json">
    {
      "AMP_Product_Page": {
        "sticky": true,
        "variants": {
          "Original": 50,
          "Variant_1": 50
        }
      }
    }
  </script>
</amp-experiment>

3. Code for analytics

<amp-analytics id='analytics1' type='googleanalytics'>
    <script type='application/json'>
    {
        "vars": {
        "account": "UA-105350-7"
        },
        "requests": {
        "experiment": "${pageview}&xid=${xid}&xvar=${xvar}"
        },
        "triggers": {
            "trackPageview": {
            "on": "visible",
            "request": "experiment",
            "vars": {
                "xid": "fB2hAs9HS2WgWqe332c6Ow",
                "xvar": "VARIANT(AMP_Product_Page)"
            }
        }
        }
    }
    </script>
</amp-analytics>

4. Created an experiment in Google Optimize

I created an experiment in Google Optimize and used the ID in the code above. I can also see the experiment in Google Analytics, it has 0 sessions, though.


I've also added some basic CSS rules and they are working fine.

The code above is live and I can see the experiment running on the site, also the <body> tag has an attribute amp-x-amp_product_page="Variant_1".


Google Analytics requests

I have a Google Analytics integration deployed using GTM AMP container and it's working fine.

Now, when I look at the requests made by Google Analytics, here's what I see:

  1. Pageview request (OK)
  2. Second pageview request with experiment data (status 302)

enter image description here

enter image description here

enter image description here

That second request seems not to make it to GA.

enter image description here

enter image description here


I tried sending experiment data with an event, but it seems like xid and xvar are not allowed variables for an event in amp-analytics.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Silver Ringvee
  • 5,037
  • 5
  • 28
  • 46
  • Have you figured this out? I have the same issue. – chris Jan 10 '18 at 14:09
  • Not yet @chris. Still doing some heavy debugging and testing of possible solutions. Will post here if I find something. Oh, and please do the same if you manage to find the solution. – Silver Ringvee Jan 10 '18 at 15:25
  • I just got it working by moving the experiment and analytics code blocks (your 2 and 3) from head to body. I hope this helps! – chris Jan 11 '18 at 10:08
  • In my case, they've been in the body all the time. I'm currently using events to send data to GA, although this way I can't use the content experiments and Google Optimize features. – Silver Ringvee Jan 11 '18 at 11:37
  • 1
    Somewhere I read the variants should be numbered instead of named in . So in your case they should be "0" and "1" instead of "Original" and "Variant_1". Worth a try... – chris Jan 11 '18 at 15:05
  • Whoa, that seems to be it! Will do some more testing but I can already see active users in Google Optimize. You might want to submit it as an answer so I could accept it. Thanks! – Silver Ringvee Jan 12 '18 at 13:45
  • Great! It's always good when the tons of irrelevant (to me) info I had to read can at least help somebody else... – chris Jan 12 '18 at 17:05

1 Answers1

4

Variants should be numbered instead of named in . So in your case they should be "0" and "1" instead of "Original" and "Variant_1".

chris
  • 649
  • 7
  • 26