// Set your API key and channel ID
const API_KEY = AIzaSyDLEiyLMMV-W_lcnHuN3Vv-BH5DgXQ5npA;
const CHANNEL_ID = UCT7B0Tm4iEqL528rCKZAJYQ;

// Set the start and end dates for your analytics data
const START_DATE = 2021-12-01;
const END_DATE = new Date().toISOString().slice(0, 10);

// Construct the API request URL
const requestUrl = `https://www.googleapis.com/youtube/v3/reports?part=views,comments,likes,dislikes&ids=channel==${CHANNEL_ID}&start-date=${START_DATE}&end-date=${END_DATE}&key=${API_KEY}`;

// Fetch the data from the API
fetch(requestUrl)
  .then(response => response.json())
  .then(data => {
    // Extract the relevant data from the API response
    const analyticsData = data.rows[0];

    // Display the data on your Squarespace page
    const viewsElement = document.getElementById('views');
    viewsElement.innerHTML = analyticsData[0];

    const commentsElement = document.getElementById('comments');
    commentsElement.innerHTML = analyticsData[1];

    const likesElement = document.getElementById('likes');
    likesElement.innerHTML = analyticsData[2];

    const dislikesElement = document.getElementById('dislikes');
    dislikesElement.innerHTML = analyticsData[3];
  })
  .catch(error => {
    console.error('Error fetching analytics data:', error);
  });