Module: GxapiHelper
- Defined in:
- app/helpers/gxapi_helper.rb
Overview
View helper for Gxapi.
Instance Method Summary collapse
-
#gxapi_experiment_js(*args) ⇒ String
Get the HTMl to load script from Google Ananlytics and setChosenVariation to tell it which one we served.
-
#gxapi_variant_name(ivar_name = :variant) ⇒ String
Get the version for a given variant.
Instance Method Details
#gxapi_experiment_js(*args) ⇒ String
Get the HTMl to load script from Google Ananlytics and setChosenVariation to tell it which one we served
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/helpers/gxapi_helper.rb', line 14 def gxapi_experiment_js(*args) # extract options opts = args.last.is_a?(Hash) ? args.pop : {} # default ivar_name = args.first || :variant unless variant = self.get_variant(ivar_name) return "" end # our return value ret = "" # first time we call this, we add the script unless @gxapi_experiment_called == true ret += self.gxapi_source(opts) Gxapi.logger.debug {"Rendered Gxapi source"} end @gxapi_experiment_called = true ret += self.get_variant_js(variant) Gxapi.logger.debug { "#{ivar_name} is now #{variant.value.name}" } ret.html_safe end |
#gxapi_variant_name(ivar_name = :variant) ⇒ String
Get the version for a given variant
43 44 45 46 47 |
# File 'app/helpers/gxapi_helper.rb', line 43 def gxapi_variant_name(ivar_name = :variant) # if we have params[ivar], we just use it return "default" unless variant = instance_variable_get("@#{ivar_name}") return variant.value.try(:name) || "default" end |