At Honeybadger, we utilize Ahoy for first-party analytics in Rails. Ahoy is highly beneficial for developers because it operates within your Rails application alongside your other data and code. Need to address a specific question about your product or website visitors? It’s just one ActiveRecord query away: Ahoy::Event.where_event(“$view”, page: “https://www.honeybadger.io/”).count
Ahoy also seamlessly integrates with Chartkick and Groupdate to visually represent your data. For instance, after installing these two libraries, you can add a chart of all page views to any Rails view: <%= line_chart Ahoy::Event.where_event("$view", page: "https://www.honeybadger.io/").group_by_hour(:time).count %>
The provided code generates a chart similar to this: Charting Ahoy data with Chartkick. Ahoy and Chartkick are excellent tools for tracking analytics and building dashboards. However, the drawback is that you must deploy your app to make changes. If you find yourself frequently deploying to update your dashboards, you might consider using Blazer. Blazer allows you to explore your data, create charts, and build dashboards using SQL. Screenshot from Blazer README.
Nevertheless, working with SQL can be complex. At Honeybadger, we have used the Ahoy+Chartkick+Blazer stack for years and recently enhanced Ahoy’s data store to send events to Honeybadger Insights. This integration enables us to explore our web analytics, create dashboards, and combine them with our other observability data. Integrating Ahoy with Honeybadger Insights.
Honeybadger Insights is a new logging/observability tool that we will soon be launching at Honeybadger. With Honeybadger Insights, you can utilize our query language, BadgerQL, to delve into your Honeybadger data (errors, uptime events, etc.) and generate charts and dashboards using BadgerQL queries. Additionally, you can send us your application logs and custom events to consolidate all your data in one location.
To integrate Ahoy with Honeybadger Insights and create a chart similar to Chartkick using BadgerQL, follow these steps:
1. If you haven’t already, install the honeybadger gem by following the Rails integration instructions.
2. If you already use the honeybadger gem, it is recommended to upgrade to the latest version. Ensure that the honeybadger gem in your Gemfile is pinned to version ~> 5.5: # Gemfile gem “honeybadger”, “~> 5.5” Then update to the latest version: bundle update honeybadger
3. Open config/initializers/ahoy.rb in a text editor and modify the default Ahoy::Store to resemble the following code:
class Ahoy::Store < Ahoy::DatabaseStore
def track_visit(data)
Honeybadger.event("ahoy_visit", data)
super(data)
end
def track_event(data)
Honeybadger.event("ahoy_event", data)
super(data)
end
def geocode(data)
Honeybadger.event("ahoy_geocode", data)
super(data)
end
def authenticate(data)
Honeybadger.event("ahoy_authenticate", data)
super(data)
end
end
That's all. To test in your development environment, you can run rails server with the HONEYBADGER_REPORT_DATA=true environment variable to temporarily disable Honeybadger's development mode. Use the following command: HONEYBADGER_REPORT_DATA=true rails server
As Ahoy collects events, you should be able to see them on the Insights tab in your Honeybadger project: Ahoy events in Honeybadger Insights
To create a chart similar to the Chartkick example mentioned earlier, enter the following BadgerQL into the query box and click Search:
filter event_type::str == "ahoy_event" | filter name::str == "$view" | stats count() by bin(1h) as date | fill date step 1h | sort date
For a detailed explanation of the BadgerQL used in this query, refer to the screencast on YouTube.
Finally, switch the Line button to visualize the data as a line chart: Ahoy chart in Honeybadger Insights
By sending our Ahoy data to Insights, we can analyze our web/product analytics and user events in the same place as our observability data. This is a significant upgrade for product-led teams like ours. If this resonates with you, feel free to check it out! Send us an email to join the beta or sign up to be notified when it launches for everyone (rest assured, we won't use your email for any other purpose).
Source link