{"id":32207756,"url":"https://github.com/jdeboer/ganalytics","last_synced_at":"2025-10-22T05:59:12.152Z","repository":{"id":8634998,"uuid":"10281989","full_name":"jdeboer/ganalytics","owner":"jdeboer","description":"Interact with Google Analytics using R","archived":false,"fork":false,"pushed_at":"2021-09-28T18:06:49.000Z","size":2313,"stargazers_count":77,"open_issues_count":21,"forks_count":29,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-10-22T05:59:09.794Z","etag":null,"topics":["analytics-api","google-analytics","google-tag-manager","r"],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jdeboer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-05-25T09:14:46.000Z","updated_at":"2025-10-06T22:37:13.000Z","dependencies_parsed_at":"2022-09-10T03:21:03.153Z","dependency_job_id":null,"html_url":"https://github.com/jdeboer/ganalytics","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/jdeboer/ganalytics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdeboer%2Fganalytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdeboer%2Fganalytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdeboer%2Fganalytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdeboer%2Fganalytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jdeboer","download_url":"https://codeload.github.com/jdeboer/ganalytics/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdeboer%2Fganalytics/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280389299,"owners_count":26322507,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-22T02:00:06.515Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analytics-api","google-analytics","google-tag-manager","r"],"created_at":"2025-10-22T05:59:07.521Z","updated_at":"2025-10-22T05:59:12.144Z","avatar_url":"https://github.com/jdeboer.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"Interactively querying Google Analytics reports\n================\nJohann de Boer\n2018-06-07\n\n\u003c!-- README.md is generated from README.rmd. Please edit that file --\u003e\n\n# ganalytics \u003cimg src=\"man/figures/logo.png\" align=\"right\" height=140/\u003e\n\n[![Travis-CI Build\nStatus](https://travis-ci.org/jdeboer/ganalytics.png?branch=master)](https://travis-ci.org/jdeboer/ganalytics)\n[![Coverage\nstatus](https://codecov.io/gh/jdeboer/ganalytics/branch/master/graph/badge.svg)](https://codecov.io/github/jdeboer/ganalytics?branch=master)\n[![CRAN\nstatus](https://www.r-pkg.org/badges/version/ganalytics)](https://cran.r-project.org/package=ganalytics)\n[![Rdoc](http://www.rdocumentation.org/badges/version/ganalytics)](http://www.rdocumentation.org/packages/ganalytics)\n\nClasses and methods for interactive use of the Google Analytics core\nreporting, real-time reporting, multi-channel funnel reporting,\nmetadata, configuration management and Google Tag Manager APIs.\n\nThe aim of this package is to support R users in defining reporting\nqueries using natural R expressions instead of being concerned about API\ntechnical intricacies like query syntax, character code escaping and API\nlimitations.\n\nThis package provides functions for querying the Google Analytics core\nreporting, real-time reporting, multi-channel funnel reporting and\nmanagement APIs, as well as the Google Tag Manager API. Write methods\nare also provided for the Google Analytics Management and Google Tag\nManager APIs so that you can, for example, change tag, property or view\nsettings.\n\n## Updates\n\nSupport for GoogleAnalyticsR integration is now available for segments\nand table filter objects. You can supply these objects to the\n`google_analytics` function in GoogleAnalyticsR by using `as()`,\nsupplying the appropriate GoogleAnalyticsR class names, which are\n`\"segment_ga4\"` for segments and `\".filter_clauses_ga4\"` for table\nfilters. Soon GoogleanalyticsR will implicitly coerce ganalytics\nsegments and table filters so that you do not need to explicitly coerce\nusing `as()`.\n\nMany new functions have been provided for writing segmentation\nexpressions:\n\n  - `Segments(...)` - define a list of segments dynamically based on one\n    or more expressions and/or a selection of built-in and/or custom\n    segments by their IDs.\n  - `Include(...)` - expressions (conditions or sequences) defining\n    users or sessions to include in the segment\n  - `Exclude(...)` - expressions (conditions or sequences) defining\n    users or sessions to exclude from the segment\n  - `PerUser(...)` - set the scope of one or more segment conditions or\n    sequences to user-level, or set the scope of a metric condition to\n    user-level.\n  - `PerSession(...)` - set the scope of one or more segment conditions\n    or sequences to user-level, or set the scope of a metric condition\n    to session-level.\n  - `PerHit(...)` - specify that a set of logically combined conditions\n    must all be met for a single hit, or set the scope of a metric\n    condition to hit-level.\n  - `Sequence(...)` - define a sequence of one or more conditions to use\n    in a dynamic segment definition.\n  - `Then(condition)` - used within a `Sequence()` to specify that this\n    condition must immediately follow the preceding condition, as\n    opposed to the default of loosely following at some point later.\n  - `Later(condition)` - similar to `Then()` but means that a condition\n    can happen any point after the preceding condition - this is how\n    conditions are treated by default in a sequence if not explicitly\n    set.\n  - `First(condition)` - similar to `Then()` but means that a condition\n    must be the first interaction (hit) by the user within the specified\n    date-range. Using `First()` is optional. Without using `First()` at\n    the start of a sequence, then the first condition does not need to\n    match the first interaction by the user. It does not make sense to\n    use `First()` anywhere else in the sequence other than at the start,\n    if used at all.\n\nMulti-channel funnel (MCF) and real-time (RT) queries can now be\nconstructed, but work is still needed to process the response from these\nqueries - stay tuned for updates on this.\n\nInstead of using `Or`, `And`, and `Not`, it is now possible to use\nfamiliar R language Boolean operators, `|` (`Or`), `\u0026` (`And`), and `!`\n(`Not`) instead (thanks to @hadley for suggestion\n[\\#2](https://github.com/jdeboer/ganalytics/issues/2)). It is important\nto keep in mind however that Google Analytics requires `Or` to have\nprecedence over `And`, which is the opposite to the natural precedence\ngiven by R when using the `|` and `\u0026` operators. Therefore, remember to\nuse parentheses `(` `)` to enforce the correct order of operation to\nyour Boolean expressions. For example `my_filter \u003c- !bounced \u0026\n(completed_goal | transacted)` is a valid structure for a Google\nAnalytics reporting API filter expression.\n\nYou can now query the Google Analytics Management API to obtain details\nin R about the configuration of your accounts, properties and views,\nsuch as goals you have defined. There are *write* methods available too,\nbut these have not been fully tested so use with extreme care. If you\nwish to use these functions, it is recommended that you test these using\ntest login, otherwise avoid using the “INSERT”, “UPDATE” and “DELETE”\nmethods.\n\nThere is also some basic support for the Google Tag Manager API, but\nagain, this is a work in progress so take care with the write methods\nabove.\n\n## Installation\n\n### 1\\. Install the necessary packages into R via the GitHub repository\n\n#### Prerequisites\n\n  - Ensure you have installed the latest version of\n    [R](https://cran.r-project.org/)\n\n#### Current stable release from CRAN\n\nYou can install the released version of ganalytics from\n[CRAN](https://CRAN.R-project.org) with:\n\n``` r\ninstall.packages(\"ganalytics\")\n```\n\n#### Current development release from GitHub\n\nAlternatively, you can execute the following statements in R to install\nthe current stable development version of ganalytics from GitHub:\n\n``` r\n# Install the latest version of remotes via CRAN\ninstall.packages(\"remotes\")\n# Install ganalytics via the GitHub repository.\nremotes::install_github(\"jdeboer/ganalytics\")\n# End\n```\n\n### 2\\. Prepare your Google API application *(you only need to do this once)*\n\n  - Browse to \\[**Google API Console**\\]\n    (\u003chttps://code.google.com/apis/console/\u003e)\n  - Check you are **signed into Google** with the account you wish to\n    use.\n  - Choose **Create Project** from the Google API Console and give your\n    project a name (or choose an existing project if you have one\n    already).\n  - From the **APIs** page, enable the **Analytics API**. You may also\n    want to enable the **Tag Manager API** if you wish to try that.\n  - You will need to **agree** and **accept** the Google APIs and\n    Analytics API Terms of Service to proceed.\n  - Go to the **Credentials** page, click **Add credentials**, choose\n    **OAuth 2.0 client ID**, then select “Other”.\n  - Note your **Client ID** and **Client Secret** and download the JSON\n    file to your R working directory.\n\n*Note: For further information about Google APIs, please refer to the\n[References\nsection](https://github.com/jdeboer/ganalytics/blob/master/README.md#useful-references)\nat the end of this\ndocument.*\n\n### 3\\. Set your system environment variables *(this is optional but recommended)*\n\n  - Add the following two user variables:\n    \n    |   | Variable name                 | Variable value         |\n    | - | ----------------------------- | ---------------------- |\n    | 1 | `GOOGLE_APIS_CONSUMER_ID`     | `\u003cYour client ID\u003e`     |\n    | 2 | `GOOGLE_APIS_CONSUMER_SECRET` | `\u003cYour client secret\u003e` |\n    \n\n      - To do this in Windows:\n          - Search for and select **“Edit Environment Variables For Your\n            Account”** from the Start menu.\n          - Within the **Environment Variables** window, add the above\n            **User Variables** by selecting **New** and entering the\n            **Variable Name** and **Variable Value**, then click **OK**.\n            Do this for both variables listed in the table above.\n          - Click **OK**.\n          - **Restart** your computer for the new environment variables\n            to take effect.\n      - There is also a free open source utility to set environment\n        variables on Mac OS called\n        [EnvPane](https://github.com/hschmidt/EnvPane)\n      - Another method that works across platforms is to create an\n        `.Renviron` file within your active R working directory that is\n        structured like this:\n\n\u003c!-- end list --\u003e\n\n    GOOGLE_APIS_CONSUMER_ID = \u003cYour client ID\u003e\n    GOOGLE_APIS_CONSUMER_SECRET = \u003cYour client secret\u003e\n\n**Alternatively** you can temporarily set your environment variables\nstraight from R using this command:\n\n``` r\nSys.setenv(\n  GOOGLE_APIS_CONSUMER_ID = \"\u003cYour client ID\u003e\",\n  GOOGLE_APIS_CONSUMER_SECRET = \"\u003cYour client secret\u003e\"\n)\n```\n\n*Note: For other operating systems please refer to the Reference section\nat the end of this document.*\n\n### 4\\. Authenticate and attempt your first query with ganalytics\n\n  - ganalytics needs to know the ID of the Google Analytics **view**\n    that you wish to query. You can obtain this in a number of ways:\n    \n      - Using the [Google Analytics Query Explorer\n        tool](https://ga-dev-tools.appspot.com/explorer/)\n      - From the **Admin page** in Google Analytics under **View\n        Settings**, or\n      - The browser’s address bar while viewing a report in Google\n        Analytics - look for the digits between the letter **‘p’** and\n        trailing **‘/’**, e.g. `.../a11111111w22222222p33333333/` shows\n        a view ID of `33333333`.\n\n  - **Alternatively, ganalytics can look up the view ID for you:**\n    \n      - If you have access to only one Google Analytics account, with\n        one property, then ganalytics will automatically select the\n        default view for you from that property.\n      - Otherwise it will select the default view of the first property\n        from the first account that it finds in the list of accounts\n        that you have access to.\n\n  - Return to R and execute the following to load the ganalytics\n    package:\n    \n    ``` r\n    library(ganalytics)\n    ```\n\n  - If you have successfully set your system environment variables in\n    step 3 above, then you can execute the following, optionally\n    providing the email address you use to sign-in to Google Analytics:\n    \n    ``` r\n    my_creds \u003c- GoogleApiCreds(\"you@domain.com\")\n    ```\n\n  - Otherwise do one of the following:\n    \n      - If you downloaded the JSON file containing your Google API app\n        credentials, then provide the file\n        path:\n        \n        ``` r\n        my_creds \u003c- GoogleApiCreds(\"you@domain.com\", \"client_secret.json\")\n        ```\n    \n      - Or, instead of a file you can supply the `client_id` and\n        `client_secret` directly:\n        \n        ``` r\n        my_creds \u003c- GoogleApiCreds(\n          \"you@domain.com\",\n          list(client_id = \"\u003cclient id\u003e\", client_secret = \"\u003cclient secret\u003e\")\n        )\n        ```\n\n  - Now formulate and run your Google Analytics query, remembering to\n    substitute `view_id` with the view ID you wish to\n    use:\n    \n    ``` r\n    myQuery \u003c- GaQuery( view_id, creds = my_creds ) # view_id is optional\n    GetGaData(myQuery)\n    ```\n\n  - You should then be directed to *accounts.google.com* within your\n    default web browser asking you to sign-in to your Google account if\n    you are not already. Once signed-in you will be asked to grant\n    read-only access to your Google Analytics account for the Google API\n    project you created in step 1.\n\n  - Make sure you are signed into the Google account you wish to use,\n    then grant access by selecting **“Allow access”**. You can then\n    close the page and return back to R.\n\nIf you have successfully executed all of the above R commands you should\nsee the output of the default ganalytics query; sessions by day for the\npast 7 days. For example:\n\n``` \n        date sessions\n1 2015-03-27     2988\n2 2015-03-28     1594\n3 2015-03-29     1912\n4 2015-03-30     3061\n5 2015-03-31     2609\n6 2015-04-01     2762\n7 2015-04-02     2179\n8 2015-04-03     1552\n```\n\n*Note: A small file will be saved to your home directory (‘My Documents’\nin Windows) to cache your new reusable authentication token.*\n\n## Examples\n\nAs demonstrated in the installation steps above, before executing any of\nthe following examples:\n\n1.  Load the ganalytics package\n2.  Generate a `gaQuery` object using the `GaQuery()` function and\n    assigning the object to a variable name such as `myQuery`.\n\n### Assumptions\n\n**The following examples assume you have successfully completed the\nabove steps and have named your Google Analytics query object:\n`myQuery`.**\n\n### Example 1 - Setting the date range\n\n``` r\n# Set the date range from 1 January 2013 to 31 May 2013: (Dates are specified in the format \"YYYY-MM-DD\".)\nDateRange(myQuery) \u003c- c(\"2013-01-01\", \"2013-05-31\")\n\nmyData \u003c- GetGaData(myQuery)\nsummary(myData)\n\n# Adjust the start date to 1 March 2013:\nStartDate(myQuery) \u003c- \"2013-03-01\"\n# Adjust the end date to 31 March 2013:\nEndDate(myQuery) \u003c- \"2013-03-31\"\n\nmyData \u003c- GetGaData(myQuery)\nsummary(myData)\n# End\n```\n\n### Example 2 - Choosing what metrics to report\n\n``` r\n# Report number of page views instead\nMetrics(myQuery) \u003c- \"pageviews\"\n\nmyData \u003c- GetGaData(myQuery)\nsummary(myData)\n\n# Report both pageviews and sessions\nMetrics(myQuery) \u003c- c(\"pageviews\", \"sessions\")\n# These variations are also acceptable\nMetrics(myQuery) \u003c- c(\"ga:pageviews\", \"ga.sessions\")\n\nmyData \u003c- GetGaData(myQuery)\nsummary(myData)\n# End\n```\n\n### Example 3 - Selecting what dimensions to split your metrics by\n\n``` r\n# Similar to metrics, but for dimensions\nDimensions(myQuery) \u003c- c(\"year\", \"week\", \"dayOfWeekName\", \"hour\")\n\n# Lets set a wider date range\nDateRange(myQuery) \u003c- c(\"2012-10-01\", \"2013-03-31\")\n\nmyData \u003c- GetGaData(myQuery)\nhead(myData)\ntail(myData)\n# End\n```\n\n### Example 4 - Sort by\n\n``` r\n# Sort by descending number of pageviews\nSortBy(myQuery) \u003c- \"-pageviews\"\n\nmyData \u003c- GetGaData(myQuery)\nhead(myData)\ntail(myData)\n# End\n```\n\n### Example 5 - Row filters\n\n``` r\n# Filter for Sunday sessions only\nsundayExpr \u003c- Expr(~dayOfWeekName == \"Sunday\")\nTableFilter(myQuery) \u003c- sundayExpr\n\nmyData \u003c- GetGaData(myQuery)\nhead(myData)\n\n# Remove the filter\nTableFilter(myQuery) \u003c- NULL\n\nmyData \u003c- GetGaData(myQuery)\nhead(myData)\n# End\n```\n\n### Example 6 - Combining filters with AND\n\n``` r\n# Expression to define Sunday sessions\nsundayExpr \u003c- Expr(~dayOfWeekName == \"Sunday\")\n# Expression to define organic search sessions\norganicExpr \u003c- Expr(~medium == \"organic\")\n# Expression to define organic search sessions made on a Sunday\nsundayOrganic \u003c- sundayExpr \u0026 organicExpr\nTableFilter(myQuery) \u003c- sundayOrganic\n\nmyData \u003c- GetGaData(myQuery)\nhead(myData)\n\n# Let's concatenate medium to the dimensions for our query\nDimensions(myQuery) \u003c- c(Dimensions(myQuery), \"medium\")\n\nmyData \u003c- GetGaData(myQuery)\nhead(myData)\n# End\n```\n\n### Example 7 - Combining filters with OR\n\n``` r\n# In a similar way to AND\nloyalExpr \u003c- !Expr(~sessionCount %matches% \"^[0-3]$\") # Made more than 3 sessions\nrecentExpr \u003c- Expr(~daysSinceLastSession %matches% \"^[0-6]$\") # Visited sometime within the past 7 days.\nloyalOrRecent \u003c- loyalExpr | recentExpr\nTableFilter(myQuery) \u003c- loyalOrRecent\n\nmyData \u003c- GetGaData(myQuery)\nsummary(myData)\n# End\n```\n\n### Example 8 - Filters that combine ORs with ANDs\n\n``` r\nloyalExpr \u003c- !Expr(~sessionCount %matches% \"^[0-3]$\") # Made more than 3 sessions\nrecentExpr \u003c- Expr(~daysSinceLastSession %matches% \"^[0-6]$\") # Visited sometime within the past 7 days.\nloyalOrRecent \u003c- loyalExpr | recentExpr\nsundayExpr \u003c- Expr(~dayOfWeekName == \"Sunday\")\nloyalOrRecent_Sunday \u003c- loyalOrRecent \u0026 sundayExpr\nTableFilter(myQuery) \u003c- loyalOrRecent_Sunday\n\nmyData \u003c- GetGaData(myQuery)\nsummary(myData)\n\n# Perform the same query but change which dimensions to view\nDimensions(myQuery) \u003c- c(\"sessionCount\", \"daysSinceLastSession\", \"dayOfWeek\")\n\nmyData \u003c- GetGaData(myQuery)\nsummary(myData)\n# End\n```\n\n### Example 9 - Sorting ‘numeric’ dimensions (continuing from example 8)\n\n``` r\n# Continuing from example 8...\n\n# Change filter to loyal session AND recent sessions AND visited on Sunday\nloyalAndRecent_Sunday \u003c- loyalExpr \u0026 recentExpr \u0026 sundayExpr\nTableFilter(myQuery) \u003c- loyalAndRecent_Sunday\n\n# Sort by decending visit count and ascending days since last visit.\nSortBy(myQuery) \u003c- c(\"-sessionCount\", \"+daysSinceLastSession\")\nmyData \u003c- GetGaData(myQuery)\nhead(myData)\n\n# Notice that the Google Analytics Core Reporting API doesn't recognise 'numerical' dimensions as\n# ordered factors when sorting. We can use R to sort instead, such as using dplyr.\nlibrary(dplyr)\nmyData \u003c- myData %\u003e% arrange(desc(sessionCount), daysSinceLastSession)\nhead(myData)\ntail(myData)\n# End\n```\n\n### Example 10 - Session segmentation\n\n``` r\n# Visit segmentation is expressed similarly to row filters and supports AND and OR combinations.\n# Define a segment for sessions where a \"thank-you\", \"thankyou\" or \"success\" page was viewed.\nthankyouExpr \u003c- Expr(~pagePath %matches% \"thank\\\\-?you|success\")\nSegments(myQuery) \u003c- thankyouExpr\n\n# Reset the filter\nTableFilter(myQuery) \u003c- NULL\n\n# Split by traffic source and medium\nDimensions(myQuery) \u003c- c(\"source\", \"medium\")\n\n# Sort by decending number of sessions\nSortBy(myQuery) \u003c- \"-sessions\"\n\nmyData \u003c- GetGaData(myQuery)\nhead(myData)\n# End\n```\n\n### Example 11 - Using automatic pagination to get more than 10,000 rows of data per query\n\n``` r\n# Sessions by date and hour for the years 2016 and 2017:\n# First let's clear any filters or segments defined previously\nTableFilter(myQuery) \u003c- NULL\nSegments(myQuery) \u003c- NULL\n# Define our date range\nDateRange(myQuery) \u003c- c(\"2016-01-01\", \"2017-12-31\")\n# Define our metrics and dimensions\nMetrics(myQuery) \u003c- \"sessions\"\nDimensions(myQuery) \u003c- c(\"date\", \"dayOfWeekName\", \"hour\")\n# Let's allow a maximum of 20000 rows (default is 10000)\nMaxResults(myQuery) \u003c- 20000\n\nmyData \u003c- GetGaData(myQuery)\nnrow(myData)\n\n## Let's use dplyr to analyse the data\nlibrary(dplyr)\n\n# Sessions by day of week\nsessions_by_dayOfWeek \u003c- myData %\u003e%\n  count(dayOfWeekName, wt = sessions) %\u003e% \n  mutate(dayOfWeekName = factor(dayOfWeekName, levels = c(\n    \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"\n  ), labels = c(\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"), ordered = TRUE)) %\u003e% \n  arrange(dayOfWeekName)\nwith(\n  sessions_by_dayOfWeek,\n  barplot(n, names.arg = dayOfWeekName, xlab = \"day of week\", ylab = \"sessions\")\n)\n\n# Sessions by hour of day\nsessions_by_hour \u003c- myData %\u003e%\n  count(hour, wt = sessions)\nwith(\n  sessions_by_hour,\n  barplot(n, names.arg = hour, xlab = \"hour\", ylab = \"sessions\")\n)\n# End\n```\n\n### Example 12 - Using ggplot2\n\nTo run this example first install ggplot2 if you haven’t already.\n\n``` r\ninstall.packages(\"ggplot2\")\n```\n\nOnce installed, then run the following example.\n\n``` r\nlibrary(ggplot2)\nlibrary(dplyr)\n\n# Sessions by date and hour for the years 2016 and 2017:\n# First let's clear any filters or segments defined previously\nTableFilter(myQuery) \u003c- NULL\nSegments(myQuery) \u003c- NULL\n# Define our date range\nDateRange(myQuery) \u003c- c(\"2016-01-01\", \"2017-12-31\")\n# Define our metrics and dimensions\nMetrics(myQuery) \u003c- \"sessions\"\nDimensions(myQuery) \u003c- c(\"date\", \"dayOfWeek\", \"hour\", \"deviceCategory\")\n# Let's allow a maximum of 40000 rows (default is 10000)\nMaxResults(myQuery) \u003c- 40000\n\nmyData \u003c- GetGaData(myQuery)\n\n# Sessions by hour of day and day of week\navg_sessions_by_hour_wday_device \u003c- myData %\u003e% \n  group_by(hour, dayOfWeek, deviceCategory) %\u003e% \n  summarise(sessions = mean(sessions)) %\u003e% \n  ungroup()\n\n# Relabel the days of week\nlevels(avg_sessions_by_hour_wday_device$dayOfWeek) \u003c- c(\n  \"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"\n)\n\n# Plot the summary data\nqplot(\n  x = hour,\n  y = sessions,\n  data = avg_sessions_by_hour_wday_device,\n  facets = ~dayOfWeek,\n  fill = deviceCategory,\n  geom = \"col\"\n)\n\n# End\n```\n\n## Thanks to:\n\n  - Hadley Wickham @hadley\n  - Mark Edmondson @MarkEdmondson1234\n  - RStudio team\n  - R Core team\n\n## Useful references\n\n1.  [Google Analytics Core Reporting API reference\n    guide](https://developers.google.com/analytics/devguides/reporting/core/v3/reference)\n2.  [Google Analytics Dimensions and Metrics\n    reference](https://developers.google.com/analytics/devguides/reporting/core/dimsmets)\n3.  [Creating a Google API\n    project](https://developers.google.com/console/help/#creatingdeletingprojects)\n4.  [Generating an OAuth 2.0 client ID for Google\n    APIs](https://developers.google.com/console/help/#generatingoauth2)\n5.  [Using OAuth 2.0 for Installed\n    Applications](https://developers.google.com/accounts/docs/OAuth2InstalledApp)\n6.  [EnvPane utility for setting environment variables in\n    OSX](https://github.com/hschmidt/EnvPane)\n7.  [Setting environment variables in Ubuntu\n    Linux](https://help.ubuntu.com/community/EnvironmentVariables)\n\n## Notes\n\nPlease note that this project is released with a [Contributor Code of\nConduct](CONDUCT.md). By participating in this project you agree to\nabide by its terms.\n\nGoogle Analytics and Google Tag Manager are trademarks of Google.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdeboer%2Fganalytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjdeboer%2Fganalytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdeboer%2Fganalytics/lists"}