Module: Googletastic::Analytics
- Defined in:
- lib/googletastic/analytics.rb
Instance Method Summary collapse
- #create(options = {}) ⇒ Object
-
#login(options = {}) ⇒ Object
returns an array of account names you can use.
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( = {}) agent = WWW::Mechanize.new agent..load([: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 = [: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 login( = {}) 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) login_form = page.forms.first login_form.Email = [:email] login_form.Passwd = [:password] # agent.cookie_jar.save_as("something.yml") next_page = agent.submit(login_form) home = next_page.links.first.click form = home.forms_with("account_selector").first end |