Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
aJ2
Helper I
Helper I

Using an R script as data source in Power BI where the data in R is obtained from Google Analytics

Hi.

 

I have written an R script to pull data from Google Analytics and I want to use the data frame created in R to be integrated in Power BI.

However, I am encountering this error- 

 

"DataSource.Error: ADO.NET: R script error.
2018-09-03 12:00:25> Default Google Project for googleAnalyticsR is now set.
This is shared with all googleAnalyticsR users.
If making a lot of API calls, please:
1) create your own Google Project at https://console.developers.google.com
2) Activate the Google Analytics Reporting API
3) set options(googleAuthR.client_id) and options(googleAuthR.client_secret)
4) Reload the package.
2018-09-03 12:00:25> Set API cache
2018-09-03 12:00:25> No environment argument found, looked in GA_AUTH_FILE
Warning message:
package 'googleAnalyticsR' was built under R version 3.5.1
2018-09-03 12:00:26> Fetching v4 data batch...
Error : Authentication options didn't match existing session token and not interactive session
so unable to manually reauthenticate
Error in error_check(out) :
Authentication options didn't match existing session token and not interactive session
so unable to manually reauthenticate
Calls: google_analytics ... fetch_google_analytics_4 -> lapply -> FUN -> error_check
Execution halted

Details:
DataSourceKind=R
DataSourcePath=R
Message=R script error.
2018-09-03 12:00:25> Default Google Project for googleAnalyticsR is now set.
This is shared with all googleAnalyticsR users.
If making a lot of API calls, please:
1) create your own Google Project at https://console.developers.google.com
2) Activate the Google Analytics Reporting API
3) set options(googleAuthR.client_id) and options(googleAuthR.client_secret)
4) Reload the package.
2018-09-03 12:00:25> Set API cache
2018-09-03 12:00:25> No environment argument found, looked in GA_AUTH_FILE
Warning message:
package 'googleAnalyticsR' was built under R version 3.5.1
2018-09-03 12:00:26> Fetching v4 data batch...
Error : Authentication options didn't match existing session token and not interactive session
so unable to manually reauthenticate
Error in error_check(out) :
Authentication options didn't match existing session token and not interactive session
so unable to manually reauthenticate
Calls: google_analytics ... fetch_google_analy...
ErrorCode=-2147467259
ExceptionType=Microsoft.PowerBI.Radio.RScriptRuntimeException"

 

I have set the permissions for both- R and Google Analytics as public but still I am getting this error.

 

Following is the R script-

 

# 'dataset' holds the input data for this script
library(googleAnalyticsR)
library(ggplot2)

my_id <- 123456

start_date <- "2018-08-01"
end_date <- "2018-08-31"


dataset <- google_analytics(my_id, date_range = c(start_date, end_date),
metrics = c("transactions", "transactionRevenue", "transactionShipping", "transactionTax", "totalValue", "itemQuantity"),
dimensions = c("date", "channelGrouping", "sourceMedium", "transactionID", "orderCouponCode"), max= 200000 )


#View(dataset)

 

 

Kindly guide on how to get rid of this error.

5 REPLIES 5
ayush
Frequent Visitor

@aJ2 hi,

 

Did you get the solution, because I am also trying to do the same.

 

Thanks,

Ayush

Hi @ayush

 

I'm having problem when connecting the Google Analytics and Power BI using R but when I wrote an R script to connect it to smartly.io, then there was no issue.

 

Once I resolve the authentication issue of GA, will let you know at once.

Anonymous
Not applicable

HI @aJ2,

 

It seems like you are faced with authentication error when you use R script with google analytics.
After check your script, I haven't found you invoke authentication functions in r script. If you can please add it to your formula.

 

In addition, you can also take a look at following links about R with google analytics api:

Using Google Analytics with R

Google authentication types for R

Google Analytics R Tutorial

 

Regards,

Xiaoxin Sheng

Hi @Anonymous,

 

Thanks for your reply.

 

So do I need to revoke the permissions first in the R script before executing the script in Power BI?

 

I had followed the last link in your reply to integrate Google Analytics with R and then when I tried integrating the same in Power BI, the error pops up.

Anonymous
Not applicable

HI @aJ2,

 

It seems like Google Analytics R package used web browser with oauth authorization which power bi not approve.

For this scenario, I'd like to suggest you use other authorization mode:

Google authentication types for R

 

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.