skardhamar / rga

R Google Analytics
187 stars 90 forks source link

rga call cannot pass authenticating #20

Open thewzhang opened 10 years ago

thewzhang commented 10 years ago

Hi there,

I installed rga per the web site https://github.com/skardhamar/rga. Environment is R3.0.1 and Windows 8. The following is R codes (I did not place my real client.id and secret here):

library(devtools) library(rga) rga.open(instance="ga", client.id = "MyClientID(no problem)", client.secret = "MyCientSecret(no problem)")

It still brings me to google site for a code (I do not assume this happens per skardhamar's page). I got the following err after inputting it to the R console. When I used the simplified form rga.open(instance="ga") or rga.open(instance="ga", where="~/ga.rga"), the problem persists.

Error in function (type, msg, asError = TRUE) : SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Any advice? Thanks! Weihong

thewzhang commented 10 years ago

I got the codes working by adding the following line per a stackoverflow post:

options(RCurlOptions = list(capath = system.file("CurlSSL", "cacert.pem", package = "RCurl"), ssl.verifypeer = FALSE))

The question now is that all the visit stats are zero no matter what web sites I changed to monitor from my Google Analytics Admin.

Any advice? Thanks! Weihong

skardhamar commented 10 years ago

Could you please provide some code?

thewzhang commented 10 years ago

Bror, here is the codes I used. They are adapted from somewhere from the web. I passed the authentication and got all data zeros. I took out my Profile ID and used XXXXXXXX instead for purpose. Thanks! --Weihong

Connecting to Google Analytics API via R

Uses OAuth 2.0

https://developers.google.com/analytics/devguides/reporting/core/v3/ for documentation

library(devtools) library(rga)

Load lubridate to handle dates

library(lubridate)

Authenticating to GA API. Go to https://code.google.com/apis/console/ and create

an API application.  Don't need to worry about the client id and shared secret for

this R code, it is not needed

If file listed in "where" location doesn't exist, browser window will open.

Allow access, copy code into R console where prompted

Once file located in "where" directory created, you will have continous access to

API without needing to do browser authentication

options(RCurlOptions = list(capath = system.file("CurlSSL", "cacert.pem", package = "RCurl"), ssl.verifypeer = FALSE))

Code = 4/Q9b2skxC3D8akTrLDuYdEk-5JVSy.QkteyOXdlswcaDn_6y0ZQNj69m41ggI

rga.open(instance = "ga", where = "./gaIIapi")

Get (not provided) Search results.  Replace XXXXXXXX with your profile ID from GA

visits_notprovided.df <- ga$getData(XXXXXXXX,                                     start.date = "2010-09-01",                                     end.date = "2013-09-01",                                     metrics = "ga:visits",                                     filters = "ga:keyword==(not provided);ga:source==google;ga:medium==organic",                                     dimensions = "ga:date",                                     max = 1500,                                     sort = "ga:date")

names(visits_notprovided.df)<- c("hit_date", "np_visits")

Get sum of all Google Organic Search results.  Replace XXXXXXXX with your profile ID from GA

visits_orgsearch.df <- ga$getData(XXXXXXXX,                                   start.date = "2010-09-01",                                   end.date = "2013-09-01",                                   metrics = "ga:visits",                                   filters = "ga:source==google;ga:medium==organic",                                   dimensions = "ga:date",                                   max = 1500,                                   sort = "ga:date")

names(visits_orgsearch.df)<- c("hit_date", "total_visits")

Merge files, create metrics, limit dataset to just days when tags firing

merged.df <- merge(visits_notprovided.df, visits_orgsearch.df, all=TRUE) merged.df$search_term_provided <- merged.df$total_visits - merged.df$np_visits merged.df$pct_np <- merged.df$np_visits / merged.df$total_visits merged.df$yearmo <- year(merged.df$hit_date)*100 + month(merged.df$hit_date)

final_dataset = subset(merged.df, total_visits > 0)


From: Bror Skardhamar notifications@github.com To: skardhamar/rga rga@noreply.github.com Cc: thewzhang thewzhang@yahoo.com Sent: Wednesday, September 18, 2013 11:46 AM Subject: Re: [rga] rga call cannot pass authenticating (#20)

Could you please provide some code? — Reply to this email directly or view it on GitHub.