Class: TrackRelay::ClientId::AhoyVisitor

Inherits:
Object
  • Object
show all
Defined in:
lib/track_relay/client_id/ahoy_visitor.rb

Overview

Resolver that returns the current Ahoy visitor token, when the host application has the ahoy gem installed AND the controller exposes its ahoy helper.

Default position-1 entry in TrackRelay::Configuration#client_id_resolvers — between Ga (cookie-based) and Session (UUID fallback).

Duck-typed integration

This resolver does NOT require "ahoy". It probes the controller via respond_to?(:ahoy, true) so the gem boots cleanly in apps without Ahoy. When Ahoy is absent, #call returns nil and the next resolver in the chain takes over.

When Ahoy IS present, controller.ahoy returns an Ahoy::Tracker whose #visitor_token returns the visitor cookie value (no DB query). We use that public API only; nothing internal.

Instance Method Summary collapse

Instance Method Details

#call(controller:) ⇒ String?

Returns ahoy.visitor_token if available, else nil.

Parameters:

  • controller (Object)

    any controller-like object that may or may not include Ahoy::Trackable.

Returns:

  • (String, nil)

    ahoy.visitor_token if available, else nil.



27
28
29
30
31
# File 'lib/track_relay/client_id/ahoy_visitor.rb', line 27

def call(controller:, **)
  return nil unless controller&.respond_to?(:ahoy, true)

  controller.ahoy&.visitor_token
end