Module: GoogleAnalyticsMailer::UrlFor
- Defined in:
- lib/google_analytics_mailer/url_for.rb
Overview
This module is added as helper to ActionMailer objects and override the url_for default implementation to insert GA params into generated links
Instance Method Summary collapse
-
#url_for(original_url) ⇒ String
Override default url_for method to insert ga params.
-
#with_google_analytics_params(params) { ... } ⇒ String
Acts as an around filter from the given block and return its content by merging the given analytics parameters to current ones.
-
#without_google_analytics_params { ... } ⇒ String
Acts as an around filter from the given block and return its content without inserting any analytics tag.
Instance Method Details
#url_for(original_url) ⇒ String
Override default url_for method to insert ga params
10 11 12 13 14 15 16 17 |
# File 'lib/google_analytics_mailer/url_for.rb', line 10 def url_for(original_url) # Fetch final parameters calling private method params_to_add = controller.computed_analytics_params.with_indifferent_access # temporary override coming from with_google_analytics_params method params_to_add.merge!(@_override_ga_params) if @_override_ga_params.try(:any?) # Avoid parse if params not given params_to_add.empty? ? super(original_url) : builder.build(super(original_url), params_to_add) end |
#with_google_analytics_params(params) { ... } ⇒ String
Acts as an around filter from the given block and return its content by merging the given analytics parameters to current ones
41 42 43 44 45 46 47 |
# File 'lib/google_analytics_mailer/url_for.rb', line 41 def with_google_analytics_params(params, &block) raise ArgumentError, 'Missing block' unless block_given? @_override_ga_params = params capture(&block) ensure @_override_ga_params = nil end |
#without_google_analytics_params { ... } ⇒ String
Acts as an around filter from the given block and return its content without inserting any analytics tag
64 65 66 67 68 69 70 |
# File 'lib/google_analytics_mailer/url_for.rb', line 64 def without_google_analytics_params(&block) raise ArgumentError, 'Missing block' unless block_given? @_override_ga_params = Hash[VALID_ANALYTICS_PARAMS.zip([nil])] capture(&block) ensure @_override_ga_params = nil end |