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
# File 'lib/ga_cookie_parser.rb', line 12

def initialize(cookies = {})
  @utmz = cookies[:utmz]
  @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

#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



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

def parse_cookies
  parse_utmz
  parse_utma
end

#parse_utmaObject



48
49
50
51
52
# File 'lib/ga_cookie_parser.rb', line 48

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_utmzObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ga_cookie_parser.rb', line 31

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)


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

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

#utmz?Boolean

Returns:

  • (Boolean)


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

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