Class: Snackhack2::GoogleAnalytics

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(print_status: false) ⇒ GoogleAnalytics

Returns a new instance of GoogleAnalytics.



8
9
10
# File 'lib/snackhack2/google_analytics.rb', line 8

def initialize(print_status: false)
  @site = site
end

Instance Attribute Details

#site ⇒ Object

Returns the value of attribute site.



6
7
8
# File 'lib/snackhack2/google_analytics.rb', line 6

def site
  @site
end

Instance Method Details

#run ⇒ Object



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
38
39
40
# File 'lib/snackhack2/google_analytics.rb', line 12

def run
  # uses a handful of different regexs to extract the Google Analytics
  # code from sites. This is used by the site admin to track and mesaure 
  # people who visit the site. This could be used to find more sites 
  # they own where they re-use the code.
  gas = []
  a = Snackhack2.get(@site).body
  case a
  when /UA-\d{8}-\d/
    gas << a.match(/UA-\d{8}-\d/).to_s
  when /GTM-[A-Z0-9]{7}/
    gas <<  a.match(/GTM-[A-Z0-9]{7}/).to_s
  when /G-([0-9]+([A-Za-z]+[0-9]+)+)/
    gas << a.match(/G-([0-9]+([A-Za-z]+[0-9]+)+)/).to_s
  when /G-[A-Za-z0-9]+/
    gas << a.match(/G-[A-Za-z0-9]+/).to_s
  when /GT-[A-Za-z0-9]+/
    gas << a.match(/GT-[A-Za-z0-9]+/).to_s
  else
    puts '[+] No Google Analytics found :('
  end
  if @print_status
    gas.each do |g|
      puts g
    end
  else 
    return gas
  end
end