Ask A Question

Notifications

You’re not receiving notifications from this thread.

Tracking Metrics with Ahoy and Blazer Discussion

Awesome episode! Thanks Chris!

Reply
Masud Rana Hossain Masud Rana Hossain

Awesome episode

Reply

this is great, good demo on ahoy and blazer!

Reply

great video, thank for sharing it !

Ahoy is a wonderfull gem when it comes to track !
I also use Ahoy::Event to track visit duration and sometimes to create heatmap of my page :p

more information if you want : http://www.tuto-ruby-gratui...

this is my free rails tutorial, it's in french but code is understandable :p

Reply

That's really cool, thanks for sharing!

Reply

If using the webpacker and the latest ahoy 2.0, my browser's console returns: "ahoy is not defined", but a ruby side are working good! Can I fix that?
application.js
import ahoy from "ahoy.js";

Reply
Any thoughts on the best way to get Longitude and Latitude as part of the tracking of visits from ahoy?  it defaults to city/state/country but blazer says it needs longitude and latitude for auto generating maps.
Reply

I haven't actually used it myself but you could try the Geocoder Gem and which will take an address and give you coordinates with Geocoder.coordinates(location)

Reply

Hey, Chris! It looks like a lot has changed with ahoy in the past two years. Any way you could update this?

Reply

I don't think a whole lot has changed. They have instructions for using it with Webpacker now, but it seems mostly the same to me. Are you talking about anything specific?

Reply

No, it turns out I have a Rails 5 app that uses Webpacker, and what I implemented was apparently causing confusion in my app. I took the Webpacker stuff out and it works fine now. Thanks, anyway!

Reply

Hey Chris, does ahoy_matey only integrate with the devise User model? My colleague and I have been attempting to integrate it with another model called Product -- ignoring the User model altogether. Changing t.references :user to t.references :product.

Our app does not have user auth, and we just want to track visits and events in our Product model.

Thanks,

Reply

Yeah, should be able to set it up without Users. That's what guests are anyways, they don't have a User. You can always ask on the GitHub issues for it and get tips from the author. 👍

Reply

Does anybody have any examples of using Ahoy::Events in Blazer?? It seems the two should marry nicely, but I'm struggling to find any examples.

Blazer + Ahoy::Visits is easy, all the data points are proper fields... but with Ahoy::Events each useful piece of data is within Json and so Blazer won't parse it... (do I need to change field to JsonB??)

I want to track playback and video performance analytics (easy to do in Ahoy) and then display some of it in Blazer. But I can't work out how to delve into the properties of an Event/Visit?? Any clues?

Example: I can search by an event like "User Pressed Play" but I want to know [event].video_id or [event].current_playback_time in Blazer... then I can do average time played, number of playbacks per user, etc.

TIA

Reply

When I installed Ahoy, I just changed the migration to have the data type be JSONB and haven't experienced any issues.

From there, you could query in Blazer using regular SQL (perhaps like):

SELECT CAST((properties->>'video_id') AS INTEGER)
  FROM ahoy_events
 WHERE ahoy_events.name = 'User Pressed Play'
   AND ahoy_events.time >= '2020-12-01 00:00:00';

This assumes that you have a field called 'video_id' in your properties hash. Basically we're fetching the string value from JSONB and then casting it to an intger. You could also join on that, potentially, like:

SELECT ahoy_events.*, videos.*
  FROM ahoy_events
  JOIN videos ON videos.id = CAST((properties->>'video_id') AS INTEGER)
 WHERE ahoy_events.name = 'User Pressed Play'
   AND ahoy_events.time >= '2020-12-01 00:00:00';

I hope this gives you some ideas. If you have something else in mind, let me know, maybe I can assist further.

Reply

Anyone using Ahoy on rails 7? Server side is working fine but getting errors on client side that "ahoy is not defined"

gem file

gem "ahoy_matey"

models/ahoy/event.rb

class Ahoy::Event < ApplicationRecord
  include Ahoy::QueryMethods

  self.table_name = "ahoy_events"

  belongs_to :visit
  belongs_to :user, optional: true
end

models/ahoy/event.rb

class Ahoy::Visit < ApplicationRecord
  self.table_name = "ahoy_visits"

  has_many :events, class_name: "Ahoy::Event"
  belongs_to :user, optional: true
end

console output

player.js:23 Uncaught ReferenceError: ahoy is not defined
    at togglePlay (player.js:23:7)
    at HTMLAnchorElement.<anonymous> (player.js:14:9)

player.js

ahoy.track("Played Audio", audio_detail)

config/initializers/ahoy.rb

class Ahoy::Store < Ahoy::DatabaseStore

  Ahoy.api = true

  Ahoy.geocode = false
end

Typing ahoy.track("test") directly in console also return the same error.

Any help/thoughts?

Reply

Did you ever get this working @Brian? I have the same issue.

Reply

Yeah, I did. I’m traveling but can dig up the code (hopefully) in the next 24 hours or so. I’ll post here and let you know. If I remember correctly my issue was not using the correct path for the import.

Reply

Awesome - thanks! I'm doing a simple:

import ahoy from "ahoy.js" per the docs.....server side is working, but worried about bots - though I suppose I could wrap in a bot check using another gem?

Reply

Hey, sorry for the delay on this. I got sidetracked. Just pulled up the code and confirmed I have the Ahoy js event tracking working. I'm using the jumpstart pro template, Rails 7.0.4, ruby 3.1.2p20.

Here's some relevant code in case you have not found a working solution.

Calling Ahoy.js from inside stimulus controller.

import { Controller } from "@hotwired/stimulus"
import { Turbo } from "@hotwired/turbo-rails"
import ahoy from "ahoy.js";

....
ahoy.track("event_name", { foo_event_name: 'foo'})

gem file

gem "ahoy_matey"

initializers/ahoy.rb

class Ahoy::Store < Ahoy::DatabaseStore
end

# set to true for JavaScript tracking
Ahoy.api = true

Ahoy.geocode = false

Happy to share whatever else might be helpful and I'll try to be more responsive. Also, if you have not checked out the GoRails discord you should. I've been able to get lots of good support for this type of stuff there.

Reply

I'm looking to track downloads of mp3 files that are stored using ActiveStorage with Ahoy and data visualized with Blazer. Anyone got any resources for how to do this tracking of ActiveStorage with Ahoy?

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.