Git Product home page Git Product logo

rgoogleanalytics's Introduction

This repo is the new home for the RGoogleAnalytics library migrated from Google Code SVN

What is it

RGoogleAnalytics is a R Wrapper around the Google Analytics API. It allows fast and easy data extraction in R so that further statistical analysis can be run on the data

Key Features

  • Provides Access to v3 of the Google Analytics Core Reporting API

  • Ability to pull more than 10,000 rows of data in batches via pagination of queries

  • Ability to mitigate the effect of Query Sampling by splitting the date-range of queries and hence extract (nearly) unsampled data

  • Ability to cache data fetched from Google

  • Supports authorization via OAuth 2.0

  • In cases where queries are sampled, the output also returns the percentage of sessions that were used for the query

Installation

To get the current development version from github:

# require(devtools)
devtools::install_github("Tatvic/RGoogleAnalytics")

Dependencies

  • httr handles the underlying OAuth2.0 Authorization flow and the API requests

  • lubridate handles the date manipulation logic underlying Query Partitioning

Background

Work on RGoogleAnalytics was started by Michael Pearmain at Google. He was supported by Nick Mihailowski (Google) and Vignesh Prajapati (Tatvic).

Tutorials and Use-cases

  • Basic tutorial to get started linking Google Analytics to an API pull
  • Under development

Important Links

  • List of Valid Dimension/Metric Combinations from the Google Analytics API Reference Guide

  • Query Feed Explorer allows you to test your queries for syntatical correctness. Once verified, the query parameters can then be copied to your R Script

  • Demo link on how to use this package to extract data from Google Analytics.

rgoogleanalytics's People

Contributors

dikesh avatar jerrywho avatar kushantatvic avatar lucymcgowan avatar yui-knk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rgoogleanalytics's Issues

Unused Arguments

Hi,

I've been working with the RGoogleAnalytics package to set up data extraction from GA into R. However when following the steps from the manual and writing the following script:

query.list <- Init(start.date = "2017-08-01",
end.date = "2017-09-01",
dimensions = "ga:sourceMedium",
metrics = "ga:sessions",
max.results=1000,
table.id = "ga:80023194")

I keep on having the following error message:

Error in Init(start.date = "2017-08-01", end.date = "2017-09-01", dimensions = "ga:sourceMedium", :
unused arguments (max.results = 1000, table.id = "ga:80023194")

i'm quite convinced that i need to fill the table.id argument to select the preferred view but it for some reason R says no.

I'm using the RGoogleAnalyticsPremium package because the regular version was not available for R version 3.4.4.

Kind regards,

Paul

can we get some month level data from RGoogleAnalytics?

Until now, I was using RGoogleAnalytics package to get metrics like, users, averagetime on page, etc for particular links.

Now, I need to prepare monthly reports on overall website performance for example what were the number of users, pageviews, unique pageviews, average session duration, bounce rate, sessions etc. for the month of may.

I am using the below query to get that data

library(RGoogleAnalytics)
load("gaOAuth_token")
ValidateToken(gaOAuth_token)

tableID_pages <- "ga:8291209"
reportFilters <- paste0("ga:pagePathLevel1==", "/newshour/")

start_date <-  "YYYY-MM-DD"
end_date <- "YYYY-MM-DD"

query.list <- Init(start_date, 
                   end_date,
                   dimensions = NULL,
                   metrics = "ga:users, 
                              ga:newUsers, 
                              ga:pageviews, 
                              ga:uniquePageviews, 
                              ga:AvgSessionDuration,
                              ga:bounceRate,gaOAuth_token,
                              ga:sessions,
                              ga:avgTimeOnPage",
                   max.results = 10000,
                   table.id = tableID_pages)

ga.query <- QueryBuilder(query.list)

ga.data <- GetReportData(ga.query, gaOAuth_token)

however i am running into an error

Error in ParseDataFeedJSON(GA.Data) : 
  code : 400 Reason : Invalid value 'ga:pageviews, 
                              ga:uniquePageviews'. Values must match the following regular expression: 'ga:.+'

Am I doing something wrong?

Dimensions param is not nullable in Init

The Init function does not work when it is passed a parameter dimensions=NULL, and it does not work when dimensions are unspecified (i.e. the default argument is used). However on page 5 of the CRAN documentation it states dimensions are optional in the Init function.

The call fails with Error in if (!grepl("ga: (...) argument is of length zero

Requesting is lapsing when we used RGoogleAnalytics Package in RApache

Hello Tatvic Team,

     we are getting the strange issue when we use RGoogleAnalytics in the RApache code.

ISSUE : unable to get the request ( post/get) parameters into the Apache server occasionally, except RGoogleAnalytics package the code is working fine for all the packages.

FormCode
form

rapachecode

*ERROR *
function (url = NULL, config = list(), ..., body = NULL, encode = c("multipart",
"form", "json"), multipart = TRUE, handle = NULL)

we have installed RApache in centos 6

please suggest us how to proceed.

Bug in GetReportData()?

I was using RGoogleAnalytics without any trouble in June and July of this year. I went back to re-run the code Friday and today and now all queries using GetReportData() return this error:

Error in ParseDataFeedJSON(GA.Data) : 
  code : 401 Reason : Invalid Credentials

After verifying that my credentials and table ID are correct, I found an old thread started in 2012 on Google Groups which indicated that this happened back then due to a change in the API (https://code.google.com/p/r-google-analytics/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20Summary&groupby=&sort=&id=4) .

Is that the case now?

I have tried both the CRAN and Github versions and gotten the same results.

Update -- I also tried creating a new client ID and secret to authenticate and got the following result:

> Auth(client.id, client.secret)
Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete.
<Token>
<oauth_endpoint>
 authorize: https://accounts.google.com/o/oauth2/auth
 access:    https://accounts.google.com/o/oauth2/token
 validate:  https://www.googleapis.com/oauth2/v1/tokeninfo
 revoke:    https://accounts.google.com/o/oauth2/revoke
<oauth_app> google
  key:    128468508459-0ttjdmr4fff01feqq2b3ferllp1iupc1.apps.googleusercontent.com
  secret: <hidden>
<credentials> error

---
> token         <- Auth(client.id,client.secret)
> save(token, file="token_file")
> # saveRDS(token, file = "token.rds")
> query.list <- Init(start.date = "2014-08-01",
+                    end.date = "2015-08-13",
+                    dimensions = c("ga:source", "ga:medium"),
+                    metrics = "ga:sessions,ga:transactions",
+                    max.results = 10000,
+                    sort = "-ga:transactions",
+                    table.id = "ga:100864528")
> 
> # Create the Query Builder object so that the query parameters are validated
> ga.query <- QueryBuilder(query.list)
> 
> # Extract the data and store it in a data-frame
> ga.data <- GetReportData(ga.query, token = token)
Error in ParseDataFeedJSON(GA.Data) : code : 401 Reason : Login Required

Using RGoogleAnalytics on Cloud-base R

Hi,

I am fine using it on my local laptop but when I put the same code to my cloud-base R, I got this error during GetReportData and ValidateToken:

Error in curl::curl_fetch_memory(url, handle = handle) :
Couldn't connect to server

Do yo have any Idea I can resolve it?

Thank you.
K

Strange "Error in GetDataFeed(query.uri) : no loop for break/next, jumping to top level" error

Hi,

I am new to GitHub, so I don't know if this is the proper way to writing an issue :(

First I want to thank you for this wonderful package you created! It is helping me a lot to transform all my dashboard from a static Excel file to a dynamic online system. I manage several Google Analytics Properties, so I am trying to automatize all my dashboards. I just need to change property and profile ID and everything works smooth.

However, with the last property and profile I have tried, I get this error: "Error in GetDataFeed(query.uri) : no loop for break/next, jumping to top level"

The R Code is absolutely the same as for every other profiles I have implemented so far, so I can not figure where the problem could be. The code looks like:

#Function for start and end of month
som <- function(x) {
  as.Date(format(x, "%Y-%m-01"))
}

#Get start and end of last month
enddate <- som(Sys.Date()) - 1
startdate <- som(som(Sys.Date()) - 1)

#Get start and end of last month but for last year
enddate.lastyear <- (som(Sys.Date())-365)-1
startdate.lastyear <- som(som(Sys.Date()) - 366)

#Get start and end of the previous month for last month
enddate.prevmonth <- (som(Sys.Date())-31)-1
startdate.prevmonth <- som(som(Sys.Date()) - 32)


# Get basic KPIS from last month

query.list <- Init(start.date = paste(c(startdate)),
                   end.date = paste(c(enddate)),
                   metrics = "ga:sessions,ga:users,ga:newUsers,ga:pageviews,ga:pageviewsPerSession,ga:avgSessionDuration,ga:bounceRate,ga:goalCompletionsAll,ga:goalConversionRateAll,ga:goalValuePerSession",
                   max.results = 10000,
                   table.id = sprintf("ga:%s",profile.id))

# Create the Query Builder object so that the query parameters are validated
ga.query <- QueryBuilder(query.list)

# Extract the data and store it in a data-frame
ga.basics.lastmonth <- GetReportData(ga.query, token)

# Sanity Check for column names
dimnames(ga.basics.lastmonth)

# Check the size of the API Response
dim(ga.basics.lastmonth)

# Get basic KPIS from last month but last year

query.list <- Init(start.date = paste(c(startdate.lastyear)),
                   end.date = paste(c(enddate.lastyear)),
                   metrics = "ga:sessions,ga:users,ga:newUsers,ga:pageviews,ga:pageviewsPerSession,ga:avgSessionDuration,ga:bounceRate,ga:goalCompletionsAll,ga:goalConversionRateAll,ga:goalValuePerSession",
                   max.results = 10000,
                   table.id = sprintf("ga:%s",profile.id))

# Create the Query Builder object so that the query parameters are validated
ga.query <- QueryBuilder(query.list)

# Extract the data and store it in a data-frame
ga.basics.lastmonth.lastyear <- GetReportData(ga.query, token)

# Sanity Check for column names
dimnames(ga.basics.lastmonth.lastyear)

# Check the size of the API Response
dim(ga.basics.lastmonth.lastyear)

and the code goes on... Even more weird: The first query is executed fine, but gives the error at the second one which have identical metrics.

I have tried reproducing the query with the Query Explorer and it is done correctly. What makes this property maybe different from the others, is that it as the last created property in GA, but I cannot believe this is the problem.

Kind Regards,
Agustín

How can I delay calls? | Getting error 403 "Quota Error: User Rate Limit Exceeded"

Hi @shahkushan1,

Often when trying to get data for periods longer than 60 days or so I will hit the User Rate Limit on my account (standard). It doesn't surprise me since we have a PerIP rate quota limit of 10 requests per second and there are a couple of other applications from the same IP permanently querying the API too.

So would there be a clean way for me to space/delay my calls to the API from R?

All I can think of is simply splitting my query into shorter periods of time and merging the results afterwards.

Thanks for your help and for the package!

RGoogleAnalytics error message: Your query matched 0 results.....

I try to extract data from several accounts in one script.
few account has data and few empty, the problem is when no data i get an error message and the script stop to run.

Error message:
Your query matched 0 results. Please verify your query using the Query Feed Explorer and re-run it.
Error in GetDataFeed(query.uri) :
no loop for break/next, jumping to top level

How to fix it and skip the empty account without stop the script.

My script:

lastday <- Sys.Date() - 1
daystorun <- as.numeric(round(difftime(Sys.Date(), '2016-07-01'), digit=0))

for(i in 1:daystorun){
start.date <- as.character(lastday - daystorun + i)
end.date <- start.date
view.id <- paste("ga:",v,sep="")
query.list <- Init(start.date = start.date,
end.date = start.date,
dimensions = "ga:date, ga:medium, ga:source, ga:campaign",
metrics = "ga:users",
#max.results = 10000,
sort = "-ga:date",
filters = "ga:medium==XXXXX;ga:campaign=@xxxxxx;ga:source==XXXXXX",
table.id = view.id)

ga.query <- QueryBuilder(query.list)
ga.data <- GetReportData(ga.query, oauth_token, paginate_query = F)
ga.data["viewID"] <- paste(v)
df<-rbind(df,ga.data)
print(paste(start.date,"_",view.id))
}
}

GetReportData() fails to run when max.results is not explicitly set when calling Init()

Hello,

I just downloaded your package off CRAN today. I created my query using Init() and passed it to QueryBuilder() without any issues. But, when I try to use GetReportData() with my query, I get the following error:

Error in if (query.builder$max.results() < kMaxDefaultRows) { :
argument is of length zero

My start and end dates are valid and in the '2015-01-01' format. My call to GetReportData looks like this:

myData <- GetReportData(query, token,
paginate_query = FALSE, # True will pull more than max rows
split_daywise = TRUE # True will query one day at a time to avoid sampling
)

This is my first time using RGoogleAnalytics after your webinar in January. Forgive me if I'm making a noob mistake but I think this is an issue with the GetReportData() function.

Thanks!

CRAN compliance

Hi,
I see Rgoogleanalytics is not in CRAN anymore because lack of maintenance. I use the package a lot and I am willing to support keeping the package compliance to CRAN as a contributor.
Regards,
Manuel

Authorizer ERROR

Hello. I am tasting u pack. and when i try to auth, i have this massege
Error in authorizer(authorize_url, is_interactive) :
httpuv package required to capture OAuth credentials.

SSL certificate problem: self signed certificate in certificate chain

Hi, I'm basing my code off of this setup code: https://github.com/Tatvic/RGoogleAnalytics/blob/master/demo/data_extraction_demo.R

When I try running it sometimes, I'll get this error:

> ValidateToken(token)
Error in curl::curl_fetch_memory(url, handle = handle) : 
  SSL certificate problem: self signed certificate in certificate chain

Has anyone else run into this? I'm new to using R for API-related purposes, so if someone could help point me to a workaround for this I'd be very thankful!

Filtering with hyphenated values

I can't figure out how to bring back data with hyphenated values and have tried enough configurations that makes me think it might be a bug.

For example:

"ga:pagePath%3D~blue-cars"

I want to match all paths containing the substring blue-cars. The regex is greedy so I don't need anchors.

The above does not work because a hyphen is a something (to) something in regex. E.g. 1-9.

If I do

"ga:pagePath%3D~blue\-cars"

R will escape the hyphen because there is a backslash in the string, so this is not correct syntactically.

If I do

"ga:pagePath%3D~blue\\-cars"

This works but it does not retrieve any data from GA. I know there is data for these page tracks because I can see it in the frontend. I can successfully retrieve data if I just use

"ga:pagePath%3D~cars"

This works as expected.

Oauth issue 401

Hi yes I get this error despite getting the success message va the webbrowser ...Authentication complete. Please close this page and return to R.

when i then to try to get the Token : Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete.
Error in oauth2.0_access_token(endpoint, app, code = code, user_params = user_params, :
Unauthorized (HTTP 401). Failed to get an access token.

whats odd is that I very carefully copied the ClientID and Client Secret to the RScript? ..any help much appreciated and thxvm for the R scripts and packages btw kind regards Andrew

Retrieve data from Multi Channel Funnel Reporting API

Is there a way to access the Multi Channel Funnel Reporting API with RGoogleAnalytics?

The idea is to use the authentication process and query builder from RGoogleAnalytics to additionally access the MCF API.

# Create the query object
query.list <- Init(start.date = "2014-11-01",
                   end.date = "2014-11-01",
                   dimensions = "mcf:sourcePath",
                   metrics = "mcf:totalConversions",
                   max.results = 1000,
                   table.id = "ga:**********")
# Create the query object
ga.query <- QueryBuilder(query.list)
# Fire the query to the Google Analytics API
ga.df <- GetReportData(ga.query, gaToken)

Leads to an error:

> ga.df <- GetReportData(ga.query, gaToken)
Error in ParseDataFeedJSON(GA.Data) : 
  code : 400 Reason : Invalid value 'mcf:sourcePath'. Values must match the following regular expression: '(ga:.+)?'

However, if you change the API in ToURI.R

uri <- "https://www.googleapis.com/analytics/v3/data/ga?"

to:

uri <- "https://www.googleapis.com/analytics/v3/data/mcf?"

then you can already retrieve the link for data download. Parsing and converting data into suitable R format still have to be done.

Did you ever consider to extend RGoogleAnalytics for this approach?

I`m really looking forward to an answer!
Thanks in advance!

Error : object ‘oauth_endpoints’ is not exported by 'namespace:httr'

Hi
Firstly, you people did a great job by creating the package for getting Google Analytics data in to R in an simple way.

I am facing the following issue while loading the package.

install.packages("RGoogleAnalytics", dependencies=T)
require(RGoogleAnalytics)
Loading required package: RGoogleAnalytics
Loading required package: lubridate
Loading required package: httr
Error : object ‘oauth_endpoints’ is not exported by 'namespace:httr'

I am not able to load the package because of the error in the subject. I tried individual installing of packages, which is working, but it is still not working.

Thanks in advance

Unused Arguments

Hi I'm recieving an error when creating the query list.
Do you know why/how to avoid it?

KR,
Jens

query.list <- Init(start.date = "2015-10-28",

  •                end.date = "2015-11-04",
    
  •                dimensions = "ga:date,ga:pagePath,ga:hour,ga:medium",
    
  •                metrics = "ga:sessions,ga:pageviews",
    
  •                max.results = 10000,
    
  •                sort = "-ga:date",
    
  •                table.id = "ga:73742508")
    
    Error in Init(start.date = "2015-10-28", end.date = "2015-11-04", dimensions = "ga:date,ga:pagePath,ga:hour,ga:medium", :
    unused arguments (max.results = 10000, sort = "-ga:date", table.id = "ga:73742508")

Sampled Data Warning with Pagination - Feature Request

Hey. This is a great package that's massively helpful.

One amendment that would be nice is if when you trigger the return of sampled data when you paginate you still get the message about sampled data. It is definitely possible to have paginate = T and still get sampled data, particularly if you have a lot of traffic.

Looking at the code, this functionality only seems to exist where pagination AND split_daywise = F.

Cheers
Jacob

using split_daywise = T results in dates being 1 day behind submitted dates

I'm having an issue where start and end dates are off by 1 day.

The following is a toy example, but I am able to reproduce the error on my machine using this. (The query I want to run is for the full month, which is why I'm using split_daywise = T, delay = 5 )

load("token_file") # in the actual code I use a full local path to the token file

ValidateToken(token)

query.list <- Init(start.date = "2016-05-01",
                   end.date = "2016-05-02",
                   dimensions = "ga:date,ga:source,ga:medium,ga:deviceCategory",
                   metrics = "ga:sessions",
                   max.results = 10000,
                   table.id = "ga:xxxxxxxxxx"
)

ga.query <- QueryBuilder(query.list)

ga.data <- GetReportData(ga.query, token, split_daywise = T, delay = 5)

This will return:

Access Token is valid.
[ Run 0 of 1] Getting data for 2016-04-30
[ Run 1 of 1] Getting data for 2016-05-01
The API returned 460 results.

Anyone else experiencing this or have an idea what could be causing it?

The only date arithmetic I've found in the execution of the above is in SplitQueryDaywise() in line 43 where date <- format(as.POSIXct(start.date) + days(i), '%Y-%m-%d') but it's addition, and my issue is that 1 day is being subtracted.

If I execute that code directly in the console, the calculation is performed correctly, returning "2016-05-01" for i = 0 and start.date = "2016-05-01"

When I set a breakpoint at line 41 in SplitQueryDaywise() and step through the calculation, everything looks fine. I hit next and i is set to 0. I hit next again, and date <- format(as.POSIXct(start.date) + days(i), '%Y-%m-%d') evaluates to "2016-04-30"

Also, if I drop the split_daywise and delay arguments, the ga:date data shows that the data is correctly from 5/1 and 5/2. Unfortunately if I try to get the whole month, it introduces sampling, which I want to avoid. But if I split daywise, the dates are off.

System info in case it's relevant:
Windows 7 32 bit
R version 3.3.0
Rstudio 0.99.893
RGoogleAnalytics 0.1.5
lubridate 1.5.6
httr 1.1.0
digest 0.6.9

Do you plan the implementation of some caching?

When running a query with split_daywise=TRUE I would like to cache each result of a day. So when running the same command the next day most of the request would come out of the cache.

Is something like this planned? But caching should be possilbe for every kind of query.

Bug in caching design

I love this library—it's made analyzing GA data so much easier for me.

There is a bug with how caching works. Currently, the result of a query is cached, regardless of the return status. The issue is that the next time the query runs (with cache = TRUE), you'll relive the error code, even if the error came from rate limiting. What's more, because of how RGoogleAnalytics builds up the cache file name, it's not obvious how to quickly delete just the right file. This means that if you've built up a solid cache of responses over time for historical reports, you either need to spend time discovering the filename or need to delete the entire cache.

I could see a couple of better solutions here:

  1. Don't cache responses with error codes
  2. Add a 'delete cache' function for particular query params
  3. Use a library like memoise to make cache management easier

What do you think?

how to fix “Error in ParseDataFeedJSON(GA.Data) : code : 400 Reason : Invalid expression. Expression exceeds max size of 4096”

I am trying to get the eventLabels from the google analytics api through R

I tried reducing the number of max.results in the Init() function. I still keep getting the error

# get eventLabel which is a unique video ID of the video on the website.
query.list <- Init(startDate,
                   endDate,
                   dimensions = "ga:eventLabel",
                   metrics = "ga:totalEvents",
                   filters = reportFiltersCOVE,
                   max.results = 10000,
                   table.id = tableID_events)
# run query
ga.query <- QueryBuilder(query.list)
# save data for google analytics in data.nko.COVE
data.nko.COVE <- GetReportData(ga.query,
                               gaOAuth_token)

I get the following error

"Error in ParseDataFeedJSON(GA.Data) :    code : 400 Reason : Invalid expression. Expression exceeds max size of 4096"

when I run the last piece of code

data.nko.COVE <- GetReportData(ga.query,
                               gaOAuth_token)

I need help in understanding what this error means and how can I fix it?"

Any help is much appreciated

Losing auth during receiving data

Hi,

we are getting data from GA from different views (tables). With one - we have strange problem.
SOMETIMES... during receiving data... there is an error:
Error in ParseDataFeedJSON(GA.Data) : code : 401 Reason : Request had invalid authentication credentials.

We're using token file which is validated and reload just before running query.

What is strange:

  • it's very often... but not always
  • on other views - works without problem (this one is the biggest :/ )

Any idea what to check, what to change?

W.

Allow to set curl timeout value

Hi,

I guess this is due to me working in a corporate environment and thus the firewall is slowing down the connection.

I am getting the following error:

Error in curl::curl_fetch_memory(url, handle = handle) : 
  Timeout was reached

Would it be possible to allow to set the timeout value manually?

Thanks!

Errors in documentation for the GetReportData function

The examples in ?GetReportData have several errors.

  1. There is no such thing as True in R (IIRC). Everywhere where True is mentioned (both in Arguments and the Examples, this should be changed to TRUE
  2. This lines ga.query <- QueryBuilder(query.list) in the examples should be changed to query <- QueryBuilder(query.list) in order for the next lines to work.
  3. This example ga.df <- GetReportData(query, oauth_token, paginate_query=True) returns an error (even after changing True to TRUE)- not sure if this specific to my account or not, but maybe a comment should be added there either way.

Mismatch between pageviews on GA and the returned resultsof GetReportData

Hi,

I followed the instructions for linking the core API, and I seem to get results, but when I run:

query.list <- Init(start.date = "2016-05-01",
                   end.date = "2016-05-03",
                   dimensions = "ga:date,ga:pagePath",
                   metrics = "ga:pageviews",
                   max.results = 10000,
                   sort = "-ga:date",
                   table.id = "ga:xxxxx")
ga.query <- QueryBuilder(query.list)
mydata <- GetReportData(ga.query, token, split_daywise = T)

I get a mismatch between what I see on Google Analytics and the result from GetReportData. Any pointers?

Thanks and best wishing, I love your work!

Dan

Error message

Authorize the Google Analytics account

This need not be executed in every session once the token object is created

and saved

client.id <- "Included my ID"
client.secret <- ""included my client secret"
token <- Auth(client.id,client.secret)
httpuv not installed, defaulting to out-of-band authentication
Please point your browser to the following url:

https://accounts.google.com/o/oauth2/auth?client_id=810391258461-tims44fbgg9d7uedv3o7fru5b64bhv32.apps.googleusercontent.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fanalytics.readonly&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code

Enter authorization code:

Save the token object for future sessions

save(token,file="./token_file")
4/tY75jfbpwincjsoamWWS7S5bqniSeh-kIhDkf-KonbU.QjMD_bNjeJEUJvIeHux6iLZr1C5JmAI
Error: object 'tY75jfbpwincjsoamWWS7S5bqniSeh' not found

Error: couldn't connect to host

Hello,

I met an error when running "ga.df <- GetReportData(ga.query, token)":
Error in function (type, msg, asError = TRUE) : couldn't connect to host

I think it's probably because of the Great Firewall (I'm in China). In most time I visit Google Analytics through proxies in chrome. Maybe it's a solution that using 'httr' with a proxy, but I didn't work it out.

Here’s my code:
token <- Auth( XXX , XXX)
query.list <- Init(start.date = "2014-09-01",
end.date = "2014-09-10",
dimensions = "ga:date",
metrics = "ga:pageviews",
max.results = 10,
table.id = "ga:XXX ")
ga.query <- QueryBuilder(query.list)
ga.df <- GetReportData(ga.query, token)

Thanks in advance!

using RGoogleAnalytics with doParallel

Hi,

I've being running a query that takes too much time because of the wide range concerning the dates [Init(start.date,end.date,..)]. I am also using GetReportData(...,paginate_query=T,split_daywise=T).

In order to reduce the time, I've being trying to run in parallel the same query, changing only the start.date and end.date parameters. I am using the package doParallel on Windows. I am already exporting all the .GlobaEnv and the RGoogleAnalytics package to each new instance of R that is created to each core.

The problem is that this is taking much more time than if I try to run the query without parallelizing it. I couldn't get any results by doing it.

Does any one ever tried to use RGoogleAnalytics in parallel?

Using OAuth for multi-user Shiny app

I want to create a multi-user Shiny app (in my server), where users login to their own Google account and the app works with their data.

I think I will need to create a web application key in Google API manager, and with it, I will build my app and the users could click in a login button and be redirected to Google, where they can authorize the access for Analytics data.
This is possible with RGoogleAnalytics? (I think this would be similar to rga.open in the RGA package, but without the need to insert the token in the source code)

There another way to use a token which persist for more than 1 hour? (more than one month if possible).

Thanks! And thanks for this great package.

Error in ParseDataFeedJSON(GA.Data) : code : 400 Reason

From this day i have error
Error in ParseDataFeedJSON(GA.Data) :
code : 400 Reason : Invalid integer value:
Pls. help me where i can faind error?
query.list <- Init(start.date = "2013-11-28",
end.date = "2013-11-30",
dimensions = "ga:date,ga:pagePath,ga:hour,ga:medium",
metrics = "ga:sessions,ga:pageviews",
max.results = 10000000,
sort = "-ga:date",
filters = "ga:medium==referral",
table.id = "ga:********")

filtering ga:landingPagePath with character '&'

Often I have to filter landing pages with character '&', like '/index.html&channel=1'. In RGoogleAnalytics, the right way to do this seems to be: filters="ga:landingPagePath=~^/index.html&channel=1'(I want to filter all landing pages starting with '/index.html&channel=1').
However, it turns out that this filtering condition returns some really weird results, which are obviously not what I want. And by checking for some time, I think the problem hinges on character '&'. When I replace '&' with '.', it makes sense(though it is not exactly what I desire).
So anyone who knows what is the problem with character '&' in regular expression here? As I know, it doesn't work when I try to replace '&' with '&'.

Error in ParseDataFeedJSON(GA.Data) : code : 400 Reason : Invalid value '

Hi, I am getting this issue when I use the following segment and it gives me this error

query.list <- Init(start.date = "2017-11-01",
end.date = "2017-11-30",
dimensions = "ga:pagePath",
metrics = "ga:pageviews",
sort = NULL, filters = NULL,
segments = my_segment,
max.results = 1000,
table.id = "ga:104288048",
start.index=NULL)

Create the Query Builder object so that the query parameters are validated

ga.query <- QueryBuilder(query.list)

Extract the data and store it in a data-frame

ga_data <- GetReportData(ga.query, token, split_daywise = T)

Error in ParseDataFeedJSON(GA.Data) : code : 400 Reason : Invalid value '

My segment i have followed an example as below: i am looking to retrieve (i found an example pulls the top 10 pages for the last thirty days, for visits that occurred on a mobile device

my_segment_element <- segment_element("deviceCategory",
operator = "EXACT",
type = "DIMENSION",
expressions = "Mobile")

my_segment_vector <- segment_vector_simple(list(list(my_segment_element)))

my_segment_definition <- segment_define(list(my_segment_vector))

my_segment <- segment_ga4("Mobile Sessions Only",session_segment = my_segment_definition)

Error in init_oauth2

When i execute the code it gives me this error, Could you please help me solve this

Error in init_oauth2.0(self$endpoint, self$app, scope = self$params$scope, :
Unauthorized (HTTP 401). Failed to get an access token.

Google Analytics Data Mining with R (includes 3 Real Applications)

Here's my code which I am exactly using as mentioned in the Youtube tutorial but still facing an error:

Error in plot.forecast(revenue_forecast, shadebars = F) :
could not find function "plot.forecast"

CODE:
#Seasonality and trend decomposition
ts_decomp <-stl(revenue.ts, s.window = "period")
ts_decomp
plot(ts_decomp)

#Additional plots
monthplot(revenue.ts)
seasonplot(revenue.ts)

#Automted forcasting using an exponential smoothing model
fit <-ets(revenue.ts)

#check wheather residual are randomly distributed
plot.ts(fit$residuals)
accuracy(fit)

#Automated forecasting using an arima model

fit <-auto.arima(revenue.ts)

accuracy(fit)

revenue_forecast <- forecast(fit, 3)
revenue_forecast
plot.forecast(revenue_forecast,shadebars = F) #Error in plot.forecast(revenue_forecast, shadebars = F) : could not find function "plot.forecast"

Problem with ga:keyword dimension

I have some issue withe downloading data related withe the ga:keyword dimension (which is actually not the direct Analytics dimension, but it is displayed correct in the API explorer or other API scripts). While downloading the query based on the bellow scrip:
ga.query.init <- Init( start.date = "2017-10-01", end.date = "2017-10-31", dimensions = c("ga:keyword","ga:date"), metrics = c("ga:impressions"), max.results = 10000, filters = "ga:medium==cpc", table.id = "ga:xxxxxx")
The data.frame returns something strange:
keyword date impressions 9668 <U+0440><U+0430><U+0434><U+0438><U+0430><U+0442><U+043E><U+0440><U+044B> 20171001 330
The keyword is not the proper value.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.