Create a Social Media Analytics Dashboard with Google Sheets

Social media analytics dashboard

Table of Contents

Introduction

Tracking social media performance is essential for any digital marketing strategy. A custom analytics dashboard in Google Sheets can help you visualize and analyze your social media data efficiently. By leveraging Google Apps Script, you can automate data collection from various social media platforms. This tutorial will guide you through creating a custom social media analytics dashboard using Google Sheets and Apps Script.

Requirements

  • Basic knowledge of Google Sheets
  • A Google account
  • Access to social media APIs (e.g., Twitter API, Facebook Graph API)
  • Basic understanding of JavaScript (for Apps Script)

Step 1: Setting Up Google Sheets

  1. Create a New Google Sheet: Go to Google Sheets and create a new spreadsheet. Name it “Social Media Analytics Dashboard”.
  2. Create Columns: Set up columns for the metrics you want to track, such as:
    • Date
    • Platform (e.g., Twitter, Facebook)
    • Followers
    • Likes
    • Shares
    • Comments
    • Engagement Rate

Step 2: Configuring API Access

  1. Generate API Keys: For each social media platform you want to track, generate the necessary API keys. For example, for Twitter, you’ll need to create a developer account and generate an API key, API secret key, access token, and access token secret.
  2. Store API Keys Securely: Keep your API keys in a secure place. You can also store them directly in the Apps Script for ease of access.

Step 3: Writing the Apps Script

  1. Open Script Editor: In your Google Sheet, go to Extensions > Apps Script. This will open the Apps Script editor.
  2. Write the Script: Use the following sample script to fetch data from the Twitter API and populate your Google Sheet. Replace the placeholder strings with your actual API keys.
function fetchTwitterData() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
  var apiKey = 'YOUR_API_KEY';
  var apiSecretKey = 'YOUR_API_SECRET_KEY';
  var accessToken = 'YOUR_ACCESS_TOKEN';
  var accessTokenSecret = 'YOUR_ACCESS_TOKEN_SECRET';

  var service = getTwitterService(apiKey, apiSecretKey, accessToken, accessTokenSecret);
  var url = 'https://api.twitter.com/1.1/account/verify_credentials.json';
  var response = service.fetch(url);
  var data = JSON.parse(response.getContentText());

  var date = new Date();
  var followers = data.followers_count;

  sheet.appendRow([date, 'Twitter', followers, '', '', '', '']);
}

function getTwitterService(apiKey, apiSecretKey, accessToken, accessTokenSecret) {
  return OAuth1.createService('Twitter')
    .setAccessTokenUrl('https://api.twitter.com/oauth/access_token')
    .setRequestTokenUrl('https://api.twitter.com/oauth/request_token')
    .setAuthorizationUrl('https://api.twitter.com/oauth/authorize')
    .setConsumerKey(apiKey)
    .setConsumerSecret(apiSecretKey)
    .setAccessToken(accessToken, accessTokenSecret);
}
  1. Set Up Triggers: Go to the Triggers section in Apps Script (clock icon) and set up a trigger to run your fetchTwitterData function daily.

Step 4: Fetching Data from Facebook

To add Facebook data, create another function in the same Apps Script file:

function fetchFacebookData() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
  var accessToken = 'YOUR_FACEBOOK_ACCESS_TOKEN';
  var pageId = 'YOUR_FACEBOOK_PAGE_ID';
  
  var url = `https://graph.facebook.com/${pageId}/insights/page_fans?access_token=${accessToken}`;
  var response = UrlFetchApp.fetch(url);
  var data = JSON.parse(response.getContentText());

  var date = new Date();
  var followers = data.data[0].values[0].value;

  sheet.appendRow([date, 'Facebook', followers, '', '', '', '']);
}

Set up another trigger for this function to fetch Facebook data daily.

Step 5: Visualizing the Data

  1. Create Charts: Use Google Sheets’ built-in charting tools to visualize the data. Select the data range and go to Insert > Chart. Choose the type of chart that best represents your data, such as line charts for follower growth over time.
  2. Customize the Dashboard: Arrange your charts and data in a user-friendly dashboard layout. Use colors and labels to make the dashboard easy to read.

Conclusion

Building a custom social media analytics dashboard with Google Sheets and Apps Script allows you to automate data collection and visualization, saving time and providing valuable insights. This tutorial provided a step-by-step guide to setting up an automated reporting system using the Twitter and Facebook APIs.

Try
RecurPost

Schedule and Publish your posts on multiple social accounts, read and reply to incoming messages with social inbox, and collaborate with your team and clients with ease.

Scroll to Top