Module: Www::TrackingHelper
- Defined in:
- app/helpers/www/tracking_helper.rb
Overview
Helper methods for trackable elements with Analytics integration
Include this helper where you need trackable phone links or other
tracked contact elements.
Instance Method Summary collapse
-
#trackable_phone_link(phone_number: nil, link_number: nil, label: nil, class_names: nil, style: :default, icon: false, **html_options) ⇒ Object
Trackable phone link.
Instance Method Details
#trackable_phone_link(phone_number: nil, link_number: nil, label: nil, class_names: nil, style: :default, icon: false, **html_options) ⇒ Object
Trackable phone link
Generates a phone link with consistent styling.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/helpers/www/tracking_helper.rb', line 47 def trackable_phone_link(phone_number: nil, link_number: nil, label: nil, class_names: nil, style: :default, icon: false, **) # Use constants as defaults - client-side JS swaps these if ga_phone cookie exists display_number = phone_number || PhoneNumbers::TOLLFREE tel_number = link_number || PhoneNumbers::TOLLFREE_LINK # Build CSS classes based on style base_classes = %w[wy-click-to-call phone-text-link] style_classes = case style when :button %w[btn btn-outline-primary] when :footer %w[fs-4 text btn-link p-0 footer-link] when :inline %w[btn-link p-0] else %w[contact-phone] end all_classes = (base_classes + style_classes + Array(class_names&.split)).compact.join(' ') # Build the link content content = if icon safe_join([fa_icon('phone', class: 'pe-1'), label || display_number]) else label || display_number end # Build the link — aria-label must contain visible text (WCAG 2.5.3) opts = { rel: 'nofollow', class: all_classes } opts[:aria] = { label: "Call #{display_number}" } unless label.present? opts.merge!() link_to content, "tel:+#{tel_number}", **opts end |