Class: GaCookieParser::GaCookieParser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cookies = {}) ⇒ GaCookieParser

Returns a new instance of GaCookieParser.



12
13
14
15
16
17
# File 'lib/ga_cookie_parser.rb', line 12

def initialize(cookies = {})
  @utmz = cookies[:utmz]
  @utmb = cookies[:utmb]
  @utma = cookies[:utma]
  parse_cookies
end

Instance Attribute Details

#utmaObject (readonly)

Returns the value of attribute utma.



10
11
12
# File 'lib/ga_cookie_parser.rb', line 10

def utma
  @utma
end

#utma_hashObject (readonly)

Returns the value of attribute utma_hash.



10
11
12
# File 'lib/ga_cookie_parser.rb', line 10

def utma_hash
  @utma_hash
end

#utmbObject (readonly)

Returns the value of attribute utmb.



10
11
12
# File 'lib/ga_cookie_parser.rb', line 10

def utmb
  @utmb
end

#utmb_hashObject (readonly)

Returns the value of attribute utmb_hash.



10
11
12
# File 'lib/ga_cookie_parser.rb', line 10

def utmb_hash
  @utmb_hash
end

#utmzObject (readonly)

Returns the value of attribute utmz.



10
11
12
# File 'lib/ga_cookie_parser.rb', line 10

def utmz
  @utmz
end

#utmz_hashObject (readonly)

Returns the value of attribute utmz_hash.



10
11
12
# File 'lib/ga_cookie_parser.rb', line 10

def utmz_hash
  @utmz_hash
end

Instance Method Details

#parse_cookiesObject



31
32
33
34
35
# File 'lib/ga_cookie_parser.rb', line 31

def parse_cookies
  parse_utmz
  parse_utmb
  parse_utma
end

#parse_utmaObject



60
61
62
63
64
# File 'lib/ga_cookie_parser.rb', line 60

def parse_utma
  return if (@utma.nil? || @utma.empty?)
  @utma_hash = h = {}
  h[:domain_hash], h[:visitor_id], h[:initial_visit_at], h[:previous_visit_at], h[:current_visit_at], h[:session_counter] = @utma.split(".")
end

#parse_utmbObject



54
55
56
57
58
# File 'lib/ga_cookie_parser.rb', line 54

def parse_utmb
  return if (@utmb.nil? || @utmb.empty?)
  @utmb_hash = h = {}
  h[:domain_hash], h[:pageview], h[:outbound_click], h[:timestamp] = @utmb.split(".")
end

#parse_utmzObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ga_cookie_parser.rb', line 37

def parse_utmz
   return if (@utmz.nil? || @utmz.empty?)
   @utmz_hash = h = {}
   h[:domain_hash], h[:timestamp], h[:session_counter], h[:campaign_number], kv_pairs = @utmz.split(".", 5)
   
   kv_pairs && kv_pairs.split("|").each do |pair|
     k, v = pair.split("=")
     h[k.to_sym] = v if k && v
   end
   
   if h[:utmgclid]
     h[:utmcsr] = 'google'
     h[:utmcmd] = 'cpc'
   end
   
end

#utma?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/ga_cookie_parser.rb', line 27

def utma?
  !(@utma.nil? || @utma.empty?)
end

#utmb?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ga_cookie_parser.rb', line 23

def utmb?
  !(@utmb.nil? || @utmb.empty?)
end

#utmz?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/ga_cookie_parser.rb', line 19

def utmz?
  !(@utmz.nil? || @utmz.empty?)
end