Grafana: Google Analytics and Facebook Integration

Unlock real-time insights from Google Analytics and Facebook Ads with Grafana’s powerful data visualization and querying tools. Learn more

Ceyhun Enki Aksan
Ceyhun Enki Aksan Entrepreneur, Maker

Data visualization, alerting, and querying capabilities provided by Grafana, a highly practical application, will continue in this article titled What is Grafana? with integrations for Google Analytics and Facebook Ads (Ad Manager).

tip

For support regarding Google Analytics, please refer to support request.

Grafana Integrations and Plugins

Grafana can easily integrate with numerous data sources such as Graphite, Google BigQuery, MySQL, PostgreSQL, Stackdriver, CloudWatch, Azure Monitor, Oracle, Instana, JSON, and Strava, through plugins (add-ons) 1. However, for certain services, we may need to connect indirectly rather than directly. Google Analytics and Facebook Ads are the most fundamental examples. These integration methods, of course, can vary depending on specific requirements. In the method I will describe below, I will use Stitch for data transfer and PostgreSQL as the database management system 2.

Stitch

Stitch is a cloud-first and open-source platform that can be used for data transfer. With Stitch’s simple and powerful ETL (Extract, Transform, Load / Extraction, Transformation, and Loading) service, we can connect to various data sources—from MySQL and MongoDB databases to SaaS applications such as Salesforce and Zendesk—and transfer data from these sources to a designated destination 3.

Google Analytics and Facebook Ads Integration

As previously mentioned, using Stitch, we will retrieve the metrics and dimensions we need from our Google Analytics account, then transfer these data into a database. The data we will visualize in Grafana will originate from this database.

First, we need to determine the metrics and dimensions we’ll be using. For this purpose, we can use the Dimensions & Metrics Explorer4 page. This way, we can ensure our queries are working correctly and view the resulting data in tabular form. The metrics I’ll be using are User (ga:users), Session (ga:sessions), and Page Views (ga:pageviews), while the dimension(s) will be Date (ga:date). Once we place our metrics and dimensions into the respective fields using the Query Explorer5 and initiate the query, we’ll arrive at the result shown in the image below.

Google Analytics and Grafana Integration
Google Analytics and Grafana Integration

Now, we’ll need a database. One of our options is DigitalOcean. Another option is ElephantSQL[^5}6.

tip

If you’d like to securely store your data and smoothly execute the operations mentioned in this article, I definitely recommend using DigitalOcean.

You can sign up for a free trial with the ElephantSQL service. After signing up, your database will be created quickly, and you’ll receive information such as the server address, username, and database table details. We’ll use these details shortly for the Stitch integration.

Grafana Integration
Grafana Integration

Now it’s time for Stitch integration. You can sign up for free via the stitchdata.com address. Then, you need to click on the Destination link in the main menu. You’ll have options such as Amazon Redshift, Amazon S3, Microsoft Azure Synapse Analytics, Google BigQuery, Panoply, and PostgreSQL6. Our selection will be PostgreSQL7 8. After entering the database access credentials obtained previously from Elephantsql into the corresponding fields here, we can begin the integration validation process9.

Grafana
Grafana

Once the connection is established, we’ll enter the same details into the relevant fields on the Grafana screen. We can either use the Create a data source shortcut on the Grafana screen, or navigate to the Configuration section and then select the Data Sources section10.

Grafana
Grafana

After entering the details, we should click the Save & Test button to verify the connection. Once the connection is established, we can now proceed with integrating Google Analytics and Facebook Ads (Facebook Ad Manager) through the Stitch panel by clicking on the Integrations link in the main menu11 12.

Clicking on “Add Integrations” will reveal numerous options. We can quickly navigate to Google Analytics and/or Facebook Ads options via the search field. After selecting Google Analytics, we can proceed to the integration settings. We can enter a suitable definition in the Integration Name field and click the Authorize button to initiate the authorization process. Following the selection of the Google Analytics account where the integration will be implemented, we can input the previously defined metrics and dimensions into the respective fields3.

  • Metrics: User (ga:users), Session (ga:sessions), and Page Views (ga:pageviews)
  • Dimension: Day (ga:date)

After this, our integration process will begin, and the specified metrics and dimensions from the relevant Google Analytics account will be fetched and transferred to the database. Meanwhile, we will also be able to access these data sets via Grafana.

We can now repeat the above process by following the Add Integrations > Facebook Ads steps to set up Facebook Ads integration. The integration with Facebook Ads will be based on tables, rather than metrics and dimensions.

Grafana Integration
Grafana Integration

After completing the Facebook Ads integration, both our Google Analytics and Facebook Ads integrations will be listed under the Integrations header. Under this header, we will also be able to view the synchronization process and reconfigure the integrations. Depending on data volume, the synchronization process may take a little longer. Once the process completes without errors, our data will become accessible via Grafana.

Grafana Dashboard

Google Analytics, Facebook Ads, Asana, BigCommerce, Amplitude, AdRoll, AppsFlyer, GitHub, GitLab, Google Ads, Google Analytics 360, HubSpot, Intercom, Jira, LinkedIn Ads, MailChimp, Marketo, Salesforce Marketing Cloud, Segment, Shopify, Square, Stripe, SurveyMonkey, Trello, Zapier… regardless of which service or database we integrate with, Stitch now enables us to transfer our data to any desired destination. From this point forward, we can visualize the data in Grafana regardless of whether the source is a service or a database, and we can manage it through queries and set up alerts13.

Grafana Dashboard
Grafana Dashboard

For this process, all we need to do is select the Build a dashboard shortcut or the Manage option under the Dashboards menu. With New Dashboard, we can now create our own panel. We can begin the panel creation process by selecting Add Query or Choose Visualization.

Further Reading

Footnotes

  1. Plugins. Grafana Labs
  2. Stitch. Simple, extensible ETL built for data teams
  3. Stitch Integrations: Data Destinations 2
  4. Dimensions & Metrics Explorer. Google Analytics Demos & Tools
  5. Query Explorer. Google Analytics Demos & Tools
  6. Choosing a Destination. Stitch Docs 2
  7. ETL your data into your PostgreSQL data warehouse. Stitch
  8. Feature request. Google Analytics integration #6694, GitHub
  9. Basic Concepts and System Overview, Stitch Docs
  10. Grafana Plugins
  11. Everything to Grafana, Stitch
  12. Analyze your Google Analytics data with Grafana
  13. ETL your data into your PostgreSQL data warehouse