# Grab Google Analytics Data x

[googleAnalyticsR](https://code.markedmondson.me/googleAnalyticsR/) is an amazing package by Mark Edmondson

```
## setup
library(googleAnalyticsR)

## authenticate
ga_auth()

## get your accounts
account_list <- ga_account_list()

## account_list will have a column called "viewId"
account_list$viewId

## View account_list and pick the viewId you want to extract data from
ga_id <- 123794729

## simple query to test connection
## simple query to test connection
extract <- google_analytics(ga_id, 
                         date_range = c("2021-01-01", "2021-02-01"), 
                         metrics = "sessions", 
                         dimensions = c("date","medium","landingPagePath"),                                        
                        anti_sample = TRUE)
View(extract)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.rforseo.com/apis/web-analytics-google-analytics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
