A simple Ruby gem for querying Google's Chrome UX Report (CrUX) API. Retrieve real-time and historical field performance data for any URL on the web.
Add the gem to your Gemfile:
gem 'crux_api'Then run:
bundle installOr install it directly:
gem install crux_apiYou can also install directly from GitHub:
gem 'crux_api', github: 'ahojmetrics/crux-api'- Ruby 3.0+
- Rails (the gem uses
Rails.cachefor caching API responses) - A Google API key with the CrUX API enabled
Set your API key as an environment variable:
export GOOGLE_API_KEY=your_api_key_hereclient = CruxApi::Client.newThe client reads your API key from the GOOGLE_API_KEY environment variable automatically.
Fetch the latest 28-day rolling performance metrics for a URL:
result = client.get("https://example.com")Fetch month-by-month historical metrics (mobile) for a URL:
history = client.history("https://example.com")Both methods cache results for 12 hours via Rails.cache to reduce unnecessary API calls.
After checking out the repo, run bin/setup to install dependencies. Then run rake spec to run the tests. You can also use bin/console for an interactive prompt.
To install this gem locally:
bundle exec rake installTo release a new version, update the version number in version.rb, then run:
bundle exec rake releaseThis creates a git tag, pushes commits and the tag, and publishes the gem to RubyGems.org.
Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the CruxApi project's codebase and issue trackers is expected to follow the code of conduct.