File: instance_methods.rb

package info (click to toggle)
ruby-rack-google-analytics 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 164 kB
  • ctags: 48
  • sloc: ruby: 287; makefile: 8
file content (37 lines) | stat: -rw-r--r-- 841 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# This module holds all instance methods to be
# included into ActionController::Base class
# for enabling google analytics var tracking in a Rails app.
#
require "erb"

module GoogleAnalytics
  module InstanceMethods

    private

    def ga_custom_vars
      self.env["google_analytics.custom_vars"] ||= []
    end

    def ga_events
      self.env["google_analytics.event_tracking"] ||= []
    end

    protected

    # Tracks an event or goal on a page load
    #
    # e.g. writes
    # ga.('send', 'event', 'Videos', 'Play', 'Gone With the Wind');
    #
    def ga_track_event(category, action, label = nil, value = nil)
      ga_events.push(GoogleAnalytics::Event.new(category, action, label, value))
    end

    def ga_push(*attributes)
      var = GoogleAnalytics::Push.new(attributes)
      ga_events.push(var)
    end

  end
end