Amphtml: Google Analytics Not showing the page speed for AMP Pages when amp-analytics is used

Created on 27 Nov 2018  路  9Comments  路  Source: ampproject/amphtml

What's the issue?

amp-analytics implemented as per Google document at https://developers.google.com/analytics/devguides/collection/amp-analytics/ . Pageviews are shown properly. However, the page load speed is always 0 for AMP pages. For regular pages, I have sampling set to 100% so that I can get page load speed info for every page hit, as we don't get more than 50 views per day (for all of our pages combined). The AMP page I am using for testing is: https://dev.kravfighter.co.nz/krav-maga-classes/auckland-self-defence-class-timetable.amp.html .

How do we reproduce the issue?

Configure Google Analytics for AMP pages as per https://developers.google.com/analytics/devguides/collection/amp-analytics/ .

load the AMP page directly from your site (not from google amp viewer), and after allowing some time for data to be shown in the Google Analytics report, go Behavour->Site Speed->Page Timings. You'll see that AMP page shows number of views, but no timing (it's always 0).

After getting a feedback about PerformanceTimings trigger from @avimehta , my configuration looks like this (I blanked out my google analytics id below on purpose):

{
  "vars": {
    "gtag_id":"UA-XXXXXXXXX-1",
    "anonymizeIP":"",
    "config":{"UA-XXXXXXXXX-1":{"groups":"default"}}
  },
  "triggers":{
    "trackPageview":{
      "on":"visible","request":"pageview"
    },
    "performanceTiming":{"sampleSpec":{"threshold":100}}
  }
}

I also tried this:

{
  "vars": {
    "gtag_id":"UA-XXXXXXXXX-1","anonymizeIP":"",
    "config":{
      "UA-XXXXXXXXX-1":{"groups":"default"},
      "performanceTiming":{"sampleSpec":{"threshold":100}}
    }
  },
  "triggers":{
    "trackPageview":{"on":"visible","request":"pageview"},
    "performanceTiming":{"sampleSpec":{"threshold":100}}
  }
}

with no difference.

Previously, I've been trying to send ${pageLoadTime} specifically via custom metrics but this didn't work either. So, it is either something that is not working in amp-analytics in terms of sending the ${pageLoadTime} to Google Analytics, or something in Google Analytics vendor implementation for amp-analytics, that is not working. It is also possible that sampling is the issue too, and maybe the above example can't be used to set it to 100%.

What browsers are affected?

All browsers.

Which AMP version is affected?

1811202351440 . I just implemented this, so don't know if it ever worked and if so when did it stop working.

analytics

Most helpful comment

ah i see. Didn't realize that you were using gtag. Please use the snippet below for gtag:

{
  "vars": {
    "config": {
      "UA-XXXXXXXXX-1": {
        "site_speed_sample_rate": 100
      }
    }
  }
}

Specifically, "site_speed_sample_rate": 100 should be added to the config section of the tag.

All 9 comments

ah i see. Didn't realize that you were using gtag. Please use the snippet below for gtag:

{
  "vars": {
    "config": {
      "UA-XXXXXXXXX-1": {
        "site_speed_sample_rate": 100
      }
    }
  }
}

Specifically, "site_speed_sample_rate": 100 should be added to the config section of the tag.

Let me know if this doesn't work. I'll close this issue for now.

That was it! I wish Google added this into their documentation.
Thanks heaps, I spent last two weeks trying to figure it out and even Google Adwords/ Analytics support people were scratching their heads over this. Thank you once again!

Apologies for the lack of documentation. I'll look into getting this added to the documentation.

Hi @avimehta ! Your previous comment worked perfectly!

Unfortunately, since the version 0.9.98.13 it stopped working.

Is there a new format that needs to be used now?

Thanks!

@MehdiSv I am not sure what 0.9.98.13 version is. I tried this on my local page and I think sample rate is working correctly for me .

If you have a sample page that you can share, I will be able to look more into it. Additionally, Could give me details of which browser, which OS you are using? This might be a problem specific to a browser/OS.

sidenote: It is preferable to open a new issue when something breaks rather then commenting on a closed issue. Please report a new issue and feel free to refer to previous issues using #IssueId notation.

/cc @zhouyx

Thanks @avimehta for the quick answer!

I posted on the wrong github project, sorry about that!

@avimehta Is it possible that this is still an issue? I'm trying to debug my slow pages and it looks like google analytics+gtag causes pages to load too slow. Lighthouse audit tests on mobile/applied slow 3G says that the page never loaded... trace shows that it just takes seconds. "site_speed_sample_rate": 100 doesn't change anything.

@dkhan11 is this an issue with AMP pages?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

choumx picture choumx  路  3Comments

radiovisual picture radiovisual  路  3Comments

torch2424 picture torch2424  路  3Comments

westonruter picture westonruter  路  3Comments

aghassemi picture aghassemi  路  3Comments