I am trying to get Total Visits, Bounce Rate, Pages Per Visit, Avg Visit Duration, Age Distribution, Gender Distribution, Marketing Channels Distribution for companies like Zalando. Since Chat GPT can't see live structure or some other reason, the code below only returns Total visits (I assume because it doesnt seem correct) for 3 other columns (I didnt add all categories I mentioned above). Is there any way to receive the data above or not?
> function gatherSimilarWebData() {
> var sheet = SpreadsheetApp.getActiveSheet();
> var websites = ['zalando.com'];
> var startRow = 2;
> var metrics = ['Total Visits', 'Bounce Rate', 'Pages/Session'];
>
> for (var i = 0; i < websites.length; i++) {
> var website = websites[i];
> var metricsData = [];
>
> for (var j = 0; j < metrics.length; j++) {
> var metric = metrics[j];
> var url = 'https://www.similarweb.com/website/' + website + '/#overview/' + metric.toLowerCase().replace(/ /g, '-');
> var response = UrlFetchApp.fetch(url);
> var html = response.getContentText();
> var metricData = null;
> try {
> metricData = html.match(/"value":([^,}]+)/)[1];
> catch (e) {
> Logger.log("Error getting metric data for " + metric + " on " + website + ": " + e);
> }
> metricsData.push(metricData);
> }
>
> var row = startRow + i;
> sheet.getRange(row, 1).setValue(website);
> for (var k = 0; k < metricsData.length; k++) {
> sheet.getRange(row, k + 2).setValue(metricsData[k]);
> }
> }
> }
Tried Chat GPT 3.5 but couldnt solve the issue