Module: Googletastic::Analytics

Defined in:
lib/googletastic/analytics.rb

Instance Method Summary collapse

Instance Method Details

#create(options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/googletastic/analytics.rb', line 4

def create(options = {})
  agent = WWW::Mechanize.new
  agent.cookie_jar.load(options[:cookies])
  scid = "15601175" # one of the options options[:profile]
  form.fields_with("scid").first.value = scid
  next_page = agent.submit(form)
  new_analytics = "https://www.google.com/analytics/settings/add_profile?scid=#{scid}"
  # ucpr_protocol
  form = next_page.forms_with(:name => "mform").first
  form.ucpr_url = options[:domain]
  tracking = agent.submit(form)
  tracking_code = tracking.parser.xpath("//script").to_s.match(/getTracker\(["|']([^"|']+)["|']\)/).captures.first
end

#login(options = {}) ⇒ Object

returns an array of account names you can use



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/googletastic/analytics.rb', line 19

def (options = {})
  agent = WWW::Mechanize.new
  url = "https://www.google.com/accounts/ServiceLoginBox?service=analytics&nui=1&hl=en-US&continue=https://www.google.com/analytics/settings/?et=reset&hl=en&et=reset&hl=en-US"
  page = agent.get(url)
   = page.forms.first
  .Email = options[:email]
  .Passwd = options[:password]

  # agent.cookie_jar.save_as("something.yml")
  
  next_page = agent.submit()
  home = next_page.links.first.click
  
  form = home.forms_with("account_selector").first
end