Luna Lu | d1e8057 | 2019-06-05 20:58:16 | [diff] [blame] | 1 | # UseCounter Wiki |
| 2 | |
| 3 | UseCounter measures the usage of HTML and JavaScript features across all |
| 4 | channels and platforms in the wild. Feature usage is recorded per page load and |
| 5 | is anonymously aggregated. Note measurements only take place on HTTP/HTTPS |
| 6 | pages. Usages on new tab page, data URL, or file URL are not. Usages on |
| 7 | extensions is measured on a separate histogram. |
| 8 | |
| 9 | UseCounter data can be biased against scenarios where user metrics analysis is |
| 10 | not enabled (e.g., enterprises). However, UseCounter data is essential for |
| 11 | [web compat decision making](https://www.chromium.org/blink/platform-predictability/compat-tools) |
| 12 | and [the blink process for breaking changes](https://sites.google.com/a/chromium.org/dev/blink/removing-features), as it reflects the real Chrome usage with a wide fraction of coverage. |
| 13 | The results are publicly available on https://chromestatus.com/ and internally |
| 14 | (for Google employees) on [UMA dashboard](https://goto.google.com/uma-usecounter) |
| 15 | and [UKM dashboard](https://goto.google.com/ukm-usecounter) with more detailed |
| 16 | break-downs. |
| 17 | |
| 18 | |
| 19 | ## How to Add a UseCounter Feature |
| 20 | |
| 21 | UseCounter measures feature usage via UMA histogram and UKM. To add your |
| 22 | feature to UseCounter, simply: |
| 23 | + Add your feature to the blink::WebFeature enum; |
| 24 | + Usage can be measured via: |
| 25 | * MeasureAs=\<enum value\> in the feature's IDL definition; Or |
| 26 | * blink::UseCounter::Count() for blink side features; Or |
| 27 | * page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage() |
| 28 | for browser side features. |
| 29 | |
| 30 | Example: |
| 31 | ```c++ |
| 32 | enum WebFeature { |
| 33 | ... |
| 34 | kMyFeature = N, |
| 35 | ... |
| 36 | } |
| 37 | ``` |
| 38 | ``` |
| 39 | interface MyInterface { |
| 40 | ... |
| 41 | [MeasureAs=MyFeature] myIdlAttribute; |
| 42 | ... |
| 43 | } |
| 44 | ``` |
| 45 | OR |
| 46 | ```c++ |
| 47 | MyInterface::MyBlinkSideFunction() { |
| 48 | ... |
| 49 | UseCounter::Count(context, WebFeature::MyFeature); |
| 50 | ... |
| 51 | } |
| 52 | ``` |
| 53 | OR |
| 54 | ```c++ |
| 55 | MyBrowserSideFunction() { |
| 56 | ... |
| 57 | page_load_metrics::MetricsWebContentObserver::RecordFeatureUsage( |
| 58 | render_frame_host, blink::mojom::WebFeature::MyFeature); |
| 59 | ... |
| 60 | } |
| 61 | ``` |
| 62 | |
| 63 | Not all features collect URL-keyed metrics. To opt in your feature to UKM, |
| 64 | simply add your feature to |
Mason Freed | bef47320 | 2019-12-13 23:06:31 | [diff] [blame^] | 65 | [UseCounterPageLoadMetricsObserver::GetAllowedUkmFeatures()](https://cs.chromium.org/chromium/src/components/page_load_metrics/browser/observers/use_counter/ukm_features.cc) |
Luna Lu | d1e8057 | 2019-06-05 20:58:16 | [diff] [blame] | 66 | and get approval from one of the privacy owners. |
| 67 | |
| 68 | You can quickly verify that your feature is added to UMA histograms and UKM by |
| 69 | checking chrome://histograms/Blink.UseCounter.Features and chrome://ukm in your |
| 70 | local build. |
| 71 | |
| 72 | ## Analyze UseCounter Histogram Data |
| 73 | |
| 74 | ### Public Data on https://chromestatus.com |
| 75 | |
| 76 | Usage of JavaScript and HTML features is available |
| 77 | [here](https://chromestatus.com/metrics/feature/popularity). |
| 78 | Usage of CSS properties is available |
| 79 | [here](https://chromestatus.com/metrics/css/popularity). |
| 80 | |
| 81 | The data reflects features' daily usage (count of feature hits / count of total |
| 82 | page visits): |
| 83 | + On all platforms: Android, Windows, Mac, ChromeOS, and Linux. |
| 84 | + On "official" channels: stable, beta, and dev. |
| 85 | + For the most dominant milestone. |
| 86 | |
| 87 | |
| 88 | ### UMA Timeline with Formula |
| 89 | |
| 90 | Internally (sorry, Google employees only) you can query the usage of a feature |
| 91 | with break-downs on platforms, channels, etc on the |
| 92 | [UMA Timeline dashboard](https://goto.google.com/uma-usecounter). |
| 93 | |
| 94 | To create break-downs, select filters on the top of the dashboard, for example, |
| 95 | "Platform", and set the `operation` to "split by". Note that you can also see |
| 96 | data usage within Android Webview by setting a filter on "Platform". |
| 97 | |
| 98 | Select Metric: |
| 99 | + "Blink.UseCounter.Features" for HTML and JavaScript features. |
| 100 | + "Blink.UseCounter.CSSProperties" for CSS properties. |
| 101 | + "Blink.UseCounter.AnimatedCSSProperties" for animated CSS properties. |
| 102 | + "Blink.UseCounter.Extensions.Features" for HTML and JacaScript features on |
| 103 | extensions. |
| 104 | |
| 105 | In the metric panel, select "Formula" in the left-most drop-down. Then Click |
| 106 | "ADD NEW FORMULA" with: |
| 107 | ``` |
| 108 | "MyFeature" / "PageVisits" * 100 |
| 109 | ``` |
| 110 | |
| 111 | This provides timeline data for your feature usage (per page load) with |
| 112 | break-downs, which should more or less reflects the results on chromestatus.com. |
| 113 | |
| 114 | |
| 115 | ### UseCounter Feature in HTTP Archive |
| 116 | |
| 117 | HTTP Archive crawls the top 10K sites on the web and records everything from |
| 118 | request and response headers. The data is available on Google BigQuery. |
| 119 | |
| 120 | You can find pages that trigger a particular UseCounter using the following |
| 121 | script: |
| 122 | |
| 123 | ```sql |
| 124 | SELECT |
| 125 | DATE(yyyymmdd) AS date, |
| 126 | client AS platform, |
| 127 | num_url AS url_count, |
| 128 | pct_urls AS urls_percentile, |
| 129 | sample_urls AS url |
| 130 | FROM [httparchive:blink_features.usage] |
| 131 | WHERE feature = 'MyFeature' |
| 132 | ORDER BY url_percentile DESC |
| 133 | ``` |
| 134 | OR |
| 135 | |
| 136 | ```sql |
| 137 | SELECT |
| 138 | url |
| 139 | FROM [httparchive:pages.yyyy_mm_dd_mobile] |
| 140 | WHERE |
| 141 | JSON_EXTRACT(payload, '$._blinkFeatureFirstUsed.Features.MyFeature') IS NOT |
| 142 | NULL |
| 143 | LIMIT 500 |
| 144 | ``` |
| 145 | |
| 146 | You can also find pages that trigger a particular CSS property (during parsing): |
| 147 | |
| 148 | ```sql |
| 149 | SELECT |
| 150 | url |
| 151 | FROM [httparchive:pages.yyyy_mm_dd_mobile] |
| 152 | WHERE |
| 153 | JSON_EXTRACT(payload, '$._blinkFeatureFirstUsed.CSSFeatures.MyCSSProperty') |
| 154 | IS NOT NULL |
| 155 | LIMIT 500 |
| 156 | ``` |
| 157 | |
| 158 | To find pages that trigger a UseCounter and sort by page rank: |
| 159 | |
| 160 | ```sql |
| 161 | SELECT |
| 162 | IFNULL(runs.rank, 1000000) AS rank, |
| 163 | har.url AS url, |
| 164 | FROM [httparchive:latest.pages_desktop] AS har |
| 165 | LEFT JOIN [httparchive:runs.latest_pages] AS runs |
| 166 | ON har.url = runs.url |
| 167 | WHERE |
| 168 | JSON_EXTRACT(payload, '$._blinkFeatureFirstUsed.Features.MyFeature') IS NOT |
| 169 | NULL |
| 170 | ORDER BY rank; |
| 171 | ``` |
| 172 | |
| 173 | |
| 174 | ### UMA Usage on Fraction of Users |
| 175 | You may also see the fraction of users that trigger your feature at lease once a |
| 176 | day on [UMA Usage dashboard](https://goto.google.com/uma-usecounter-peruser). |
| 177 | |
| 178 | |
| 179 | ## Analyze UseCounter UKM Data |
| 180 | For privacy concerns, UKM data is available for Google employees only. |
| 181 | |
| 182 | ### UKM Dashboard |
| 183 | UKM dashboard is accessible to Google employees only. Please see [this internal |
| 184 | wiki](https://goto.google.com/usecounter-ukm-wiki) for details. |