QuickTip:   Ingesting Google Analytics API with Apache NiFi
Tags: 2020, apachenifi, googleanalytics, rest
Published: 2020-01-27 16:08:31

---
title: QuickTip:   Ingesting Google Analytics API with Apache NiFi
published: true
date: 2020-01-24 16:34:00 UTC
tags: 2020,apache-nifi,google-analytics,rest
canonical_url: 
---

## QuickTip:   Ingesting Google Analytics API with Apache NiFi 
  
  
**Design your query / test the API here:**  
  
[https://ga-dev-tools.appspot.com/query-explorer/](https://ga-dev-tools.appspot.com/query-explorer/)  
  

[![](https://1.bp.blogspot.com/-giy0Zi3pcBA/Xisbl5rkC9I/AAAAAAAAZUc/Vt0mK599f9wRJB5clPGel5mULBg3Pqj-wCLcBGAsYHQ/s640/googleAnalyticsQueryEx.png)](https://1.bp.blogspot.com/-giy0Zi3pcBA/Xisbl5rkC9I/AAAAAAAAZUc/Vt0mK599f9wRJB5clPGel5mULBg3Pqj-wCLcBGAsYHQ/s1600/googleAnalyticsQueryEx.png)
  
  
Building this NiFi flow is trivial.  
  
[![](https://1.bp.blogspot.com/--sNbG4jy4XM/Xisa7L9o4eI/AAAAAAAAZT8/F-hHwMNEdkMnydOEzHr2u7rf-CzWItS2ACLcBGAsYHQ/s640/GoogleAnalyticsnififlow.png)](https://1.bp.blogspot.com/--sNbG4jy4XM/Xisa7L9o4eI/AAAAAAAAZT8/F-hHwMNEdkMnydOEzHr2u7rf-CzWItS2ACLcBGAsYHQ/s1600/GoogleAnalyticsnififlow.png)  
  
Add your URL with tokens from the Query Explorer console.  
  
[![](https://1.bp.blogspot.com/-82tfYQSXgms/Xisa7w-aFlI/AAAAAAAAZUI/BgPma7qv1tAhlfxM9c0yUtxVwug8NvKigCLcBGAsYHQ/s640/googleAnalyticsSetUrlandSSLContext.png)](https://1.bp.blogspot.com/-82tfYQSXgms/Xisa7w-aFlI/AAAAAAAAZUI/BgPma7qv1tAhlfxM9c0yUtxVwug8NvKigCLcBGAsYHQ/s1600/googleAnalyticsSetUrlandSSLContext.png)  
  
  
You will need to reference the JRE that NiFi is using and it's cacerts if you don't want to build your own trust store.   The default password for JDK 8 is **changeit**.   No really.  
  

[![](https://1.bp.blogspot.com/-zCkK6Vbw20U/Xisa7HagYZI/AAAAAAAAZT4/ZnQSyFU1QKkA37uQebtJFeAA5PPx308DACLcBGAsYHQ/s640/GoogleAnalyticsSetSSL.png)](https://1.bp.blogspot.com/-zCkK6Vbw20U/Xisa7HagYZI/AAAAAAAAZT4/ZnQSyFU1QKkA37uQebtJFeAA5PPx308DACLcBGAsYHQ/s1600/GoogleAnalyticsSetSSL.png)
  

  

**Here are our results in clean JSON**

  

[![](https://1.bp.blogspot.com/-QZPirpXKXQI/Xisa7De5g2I/AAAAAAAAZUA/d2hYPgQXylc5of0mwr7KPn6J9obFcXYggCLcBGAsYHQ/s640/goggleanalyticsqueryresults.png)](https://1.bp.blogspot.com/-QZPirpXKXQI/Xisa7De5g2I/AAAAAAAAZUA/d2hYPgQXylc5of0mwr7KPn6J9obFcXYggCLcBGAsYHQ/s1600/goggleanalyticsqueryresults.png)

  

  

**Here are some attributes NiFi shows.**
  

[![](https://1.bp.blogspot.com/-eBeVl6I8jY4/Xisa7v6IwNI/AAAAAAAAZUE/0UewSZPM63ElHMdN4Gwyk_C8MTVB4XY3QCLcBGAsYHQ/s640/googleAnalyticsAttributes.png)](https://1.bp.blogspot.com/-eBeVl6I8jY4/Xisa7v6IwNI/AAAAAAAAZUE/0UewSZPM63ElHMdN4Gwyk_C8MTVB4XY3QCLcBGAsYHQ/s1600/googleAnalyticsAttributes.png)
  

**Example JSON Results**

  

**{**

**  "kind": "analytics#gaData",**

**  "id": "https://www.googleapis.com/analytics/v3/data/ga?ids=ga:33&metrics=ga:users,ga:percentNewSessions,ga:sessions&start-date=30daysAgo&end-date=yesterday",**

**  "query": {**

**    "start-date": "30daysAgo",**

**    "end-date": "yesterday",**

**    "ids": "ga:33",**

**    "metrics": [**

**      "ga:users",**

**      "ga:percentNewSessions",**

**      "ga:sessions"**

**    ],**

**    "start-index": 1,**

**    "max-results": 1000**

**  },**

**  "itemsPerPage": 1000,**

**  "totalResults": 0,**

**  "selfLink": "https://www.googleapis.com/analytics/v3/data/ga?ids=ga:33&metrics=ga:users,ga:percentNewSessions,ga:sessions&start-date=30daysAgo&end-date=yesterday",**

**  "profileInfo": {**

**    "profileId": "333",**

**    "accountId": "333",**

**    "webPropertyId": "UA-333-3",**

**    "internalWebPropertyId": "33",**

**    "profileName": "monitorenergy.blogspot.com/",**

**    "tableId": "ga:33"**

**  },**

**  "containsSampledData": false,**

**  "columnHeaders": [**

**    {**

**      "name": "ga:users",**

**      "columnType": "METRIC",**

**      "dataType": "INTEGER"**

**    },**

**    {**

**      "name": "ga:percentNewSessions",**

**      "columnType": "METRIC",**

**      "dataType": "PERCENT"**

**    },**

**    {**

**      "name": "ga:sessions",**

**      "columnType": "METRIC",**

**      "dataType": "INTEGER"**

**    }**

**  ],**

**  "totalsForAllResults": {**

**    "ga:users": "0",**

**    "ga:percentNewSessions": "0.0",**

**    "ga:sessions": "0"**

**  }**

**}**

  

You should have a lot more data depending on what you have Google Analytics pointing to.   From here you can use QueryRecord or another record processor to automatically covert, query or route this data.   You can infer a schema or build up a permanent one and store it in Cloudera Schema Registry.   I recommend doing that if this is a frequent process.
  
**Download a reference NiFi flow here:**  
  
[https://github.com/tspannhw/flows](https://github.com/tspannhw/flows)  
  
**References:**  
  
[https://developers.google.com/analytics/devguides/reporting/core/v4](https://developers.google.com/analytics/devguides/reporting/core/v4)  
  
[https://developers.google.com/analytics](https://developers.google.com/analytics)