Introduction

Tutorial

Part a) Setting Up Google Sheets + Analytics Add-On

  1. Follow this guide to install the add-on to your Google Sheets.
  2. Select “Add-ons” > “Google Analytics” > “Create a New Report” from the menu bar.
  3. Name it something, and select your Analytics View.
  4. Under configuration options, choose Pageviews (ga:pageviews) as your metric.
  5. The Dimensions will depend on the structure of your website. Page Path Level 1 will only return the data for Pages and Folders in the root of your website. Page Path Level 2 will return data for Pages and Folders in some folder in your root. Use the following table to decide your dimension.

Part b) Getting the data on your blog

  1. On the page where you want to show the view data, add a JavaScript file (or edit an existing JavaScript File for that page).
  2. Use Fetch API to get the CSV data and parse it using CSVToArray function from this StackOverflow Answer
url  = "The link you copied in Step 18 of Part a"
fetch(url).then((response)=>{
return response.text()
}).then((text)=>{
data = CSVToArray(text)
viewMap = {}
for(let i = 15; i < data.length; i++){
viewMap[window.location.href + data[i][0].slice(1,-1) + data[i][1]] = parseInt(data[i][2])
}
}
})

Read This On

  • Haider Ali Punjabi’s Blog
  • Medium
  • Dev.to

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store