jeudi 26 janvier 2017

method for determining data for google tracking manager

I have a method for defining data for google tracking manager. First logic organized in views, but I think this is not right. Tell, make a method in the controller(application_controller) or in the model?

def gtm_data(data_hash = nil)
  @gtm_data ||= {}

  if @dynamic_page
    gaPageUid = 'category-' + @dynamic_page.uid
  elsif @product
    gaPageUid = 'product'
  else
    gaPageUid = 'other'
  end

  @gtm_data = {
   gaLocale: @locale, gaLanguage: @lang,
    gaRegion: current_site.region, gaPageUid: gaPageUid
  }

  # setter call
  @gtm_data.merge!(data_hash) if data_hash

  @gtm_data
end

Aucun commentaire:

Enregistrer un commentaire