Youtube to Google Sheets: How to import Youtube public data
Tags: beginners, tutorial, productivity
Published: 2021-12-14 03:38:03

We use a variety of services today to support multiple use cases and so, it becomes increasingly important to be able to connect to different integrations.

Here is a step-by-step guide to **fetch YouTube metrics and add it to google sheets every day or every month**. Also get a notification while we're at it :P 

### Let's get started! 🚀

**Step 1: Creating necessary sheets to hold our statistics**

So the first step is to create two different empty set of google sheets to hold our every day and every month statistics. We're looking to create two sets of sheets like this:

![Step 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kk32a5pztkshzugxtzsl.png)
 
![Step 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f0sx55tgspb2n0bx8yjy.png) 

**Step 2: Let's start working on those integrations!!**
Go to this [sample project](https://app.canonic.dev/projects/61b78fc80b0203002d823376?utm_source=dev.to&utm_medium=organic_article&utm_campaign=30daysofcanonic_uc_3&utm_term=step2_sample_project&utm_content=day_15) and click on the top right corner to clone it. This project already has youtube integration for metrics set up. So we can simply clone it and get started.

![Step 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z22jdg8hvoub2hjmirvh.png)

**Step 3: Explore API tab**

From left hand navigation bar, move to the API tab. In the left hand panel, you'll find different divisions like - Endpoints, Scheduled triggers, DB triggers, Integration triggers, etc. In the scheduled triggers, you should find two triggers already set up.

- **dailyReporting -** Gets executed daily.
- **monthlyReporting -** Get executed monthly.

**Step 4: The dailyReporting flow**

Click on the dailyReporting trigger and it'll open up the graph for it. Our flow looks something like this:

![Step 4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0n9jwqd6l7658m5npxfj.png)

Clicking on these individual pills will reveal its settings and configurations.

**NOTE: You may need to re-authenticate yourself on each plugin as you've cloned the project.**

**Step 5: Updating configuration of integrations**

Let's start inspecting and correcting any integration settings should we have to. Click on the left most trigger will reveal its settings.

As you can check we've set it up to execute every day around 12:17AM. You can change this schedule should you want to by clicking on the trigger.

![Step 5 Trigger settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0iah9di0ujnapislgm4m.png)
 

Similarly, **Youtube integration** also has different settings that you can configure. Please move to the **auth** tab to re-authenticate in case it's required. In the optional parameters, you can define the different variables through which you want to query youtube. In this instance we're using these query parameters:

1. dimentions: day
2. endDate: 2021-12-30
3. ids: channel==INSERT_CHANNEL_ID or MINE
4. metrics: estimatedMinutesWatched
5. startDate:2021-12-12

![Step 5 Youtube Settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aiwym2d7lfflchibf1kp.png)

Very similarly to how above settings were configured, we can similarly **click on the google sheets to configure it's settings**.

- Authenticate yourself with the account that owns the recently created Google Sheet
- Put in the sheet ID (You can get that in your sheet’s url) and put in range e.g `A1:B30`
- Go to option fields there set `valueInputOption` to `RAW`
- In values, check static, then click on add item, in there type `{{1.rows.[0].[0]}` - here 1 refers to 1st webhook in the chain that is Youtube, and the array [0][0] represents the first value returned by youtube webhook.

![Google sheet settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1cchgdwg6b8gv6wge1at.png)

Finally we move to slack, and update its minimal configuration to trigger a message whenever this workflow is executed. It'll look like this:

![Slack settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pfc9arza1ot92cvox6fx.png) 

and Voila! We have our entire chain set up where

1. We trigger a workflow every day at X time
2. Where it fetches metrics from youtube
3. Adds them to google sheet
4. Sends a message on slack when done!

**Step 6: Creating the flow for monthly Reporting**

Similar to how we've created the flow for daily reporting, we'll create on for monthly reporting, where most of the queries will be similar.

We just have to change youtube query parameters, like this

- dimentions: day
- endDate: 2021-12-30
- ids: channel==INSERT_CHANNEL_ID or MINE
- metrics: likes,comments,views,estimatedMinutesWatched,averageViewDuration
- startDate: 2021-12-12

and change google sheet values like this 👇

![Step 6](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ufc8h0aagacuwyniked.png)

With these minor changes, we can modify our trigger to post youtube metrics to google sheet monthly. All of the above mentioned query parameters can be found in the documentation for google sheets and youtube.

## Conclusion

Hope this guide turns out to be a good help for you guys. You can clone the sample project directly from [here](https://app.canonic.dev/projects/61b78fc80b0203002d823376?utm_source=dev.to&utm_medium=organic_article&utm_campaign=30daysofcanonic_uc_3&utm_term=conclusion_here&utm_content=day_15).

You can also check out our other guides [here](https://dev.to/canonic/).

Join us on [discord](https://discord.gg/9dyytsM) to discuss or share with our community. Write to us for any support requests at [support@canonic.dev](https://support@canonic.dev/). Check out our [website](https://www.canonic.dev/30-days-of-canonic/?utm_source=dev.to&utm_medium=organic_article&utm_campaign=30daysofcanonic_uc_3&utm_term=conclusion_website&utm_content=day_15) to know more about Canonic.