Skip to content

ahojmetrics/crux-api

Repository files navigation

CruxApi

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.

Installation

Add the gem to your Gemfile:

gem 'crux_api'

Then run:

bundle install

Or install it directly:

gem install crux_api

You can also install directly from GitHub:

gem 'crux_api', github: 'ahojmetrics/crux-api'

Requirements

  • Ruby 3.0+
  • Rails (the gem uses Rails.cache for 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_here

Usage

Initialize the client

client = CruxApi::Client.new

The client reads your API key from the GOOGLE_API_KEY environment variable automatically.

Get real-time performance data

Fetch the latest 28-day rolling performance metrics for a URL:

result = client.get("https://example.com")

Get historical performance data

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.

Development

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 install

To release a new version, update the version number in version.rb, then run:

bundle exec rake release

This creates a git tag, pushes commits and the tag, and publishes the gem to RubyGems.org.

Contributing

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.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the CruxApi project's codebase and issue trackers is expected to follow the code of conduct.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

 
 
 

Contributors