Class: GACollectorPusher::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/ga_collector_pusher/instance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cid: nil, backup_cid: nil, timeout: 10, open_timeout: 10) ⇒ Instance

Returns a new instance of Instance.



9
10
11
12
13
# File 'lib/ga_collector_pusher/instance.rb', line 9

def initialize cid: nil, backup_cid: nil, timeout: 10, open_timeout: 10
  self.cid = cid || backup_cid
  self.timeout = timeout
  self.open_timeout = open_timeout
end

Instance Attribute Details

#cidObject

Returns the value of attribute cid.



7
8
9
# File 'lib/ga_collector_pusher/instance.rb', line 7

def cid
  @cid
end

#open_timeoutObject

Returns the value of attribute open_timeout.



7
8
9
# File 'lib/ga_collector_pusher/instance.rb', line 7

def open_timeout
  @open_timeout
end

#timeoutObject

Returns the value of attribute timeout.



7
8
9
# File 'lib/ga_collector_pusher/instance.rb', line 7

def timeout
  @timeout
end

Instance Method Details

#add_event(category: nil, action: nil, label: nil, value: nil, utmni: false) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/ga_collector_pusher/instance.rb', line 26

def add_event category: nil, action: nil, label: nil, value: nil, utmni: false
  @params = {
    t: "event",
    ec: category,
    ea: action
  }

  send_to_ga
end

#add_exception(description: nil, is_fatal: false) ⇒ Object

convert bool to integer



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ga_collector_pusher/instance.rb', line 74

def add_exception description: nil, is_fatal: false
  is_fatal_int = is_fatal ? 1 : 0

  @params = {
    t: "exception",
    exd: description,
    exf: is_fatal_int
  }

  send_to_ga
end

#add_item(transaction_id: nil, item_sku: nil, price: nil, quantity: nil, name: nil, category: nil, currency: "EUR") ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ga_collector_pusher/instance.rb', line 47

def add_item transaction_id: nil, item_sku: nil, price: nil, quantity: nil, name: nil, category: nil, currency: "EUR"
  @params = {
    t: "item",
    ti: transaction_id,
    in: name,
    ip: price.round(2),
    iq: quantity.to_i,
    ic: item_sku,
    iv: category,
    cu: currency
  }

  send_to_ga
end

#add_page_view(hostname: nil, page: nil, title: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/ga_collector_pusher/instance.rb', line 15

def add_page_view hostname: nil, page: nil, title: nil
  @params = {
    t: "pageview",
    dh: hostname,
    dp: page,
    dt: title
  }

  send_to_ga
end

#add_social(action: nil, network: nil, target: nil) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/ga_collector_pusher/instance.rb', line 62

def add_social action: nil, network: nil, target: nil
  @params = {
    t: "social",
    sa: action,
    sn: network,
    st: target
  }

  send_to_ga
end

#add_transaction(transaction_id: nil, total: nil, store_name: nil, tax: nil, shipping: nil, city: nil, region: nil, country: nil, currency: "EUR") ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/ga_collector_pusher/instance.rb', line 36

def add_transaction transaction_id: nil, total: nil, store_name: nil, tax: nil, shipping: nil, city: nil, region: nil, country: nil, currency: "EUR"
  @params = {
    t: "transaction",
    ti: transaction_id,
    tr: total.round(2),
    cu: currency
  }

  send_to_ga
end