Skip to main content

Record competitor website changes in Google Sheets & Data Studio

Subscribe to changedetection.io tutorials
Profile picture for user Stephen.Calder
By Stephen. Published , updated
Recommended minimum version: 0.71.1

A client asks: "can you tell us when our competitor changes their prices?" Good news, you can record competitor website changes in Google Sheets automatically, one row per change, without anyone copying numbers by hand.

In this tutorial I'll show you the whole thing from start to finish: a list of competitor product pages is imported into changedetection.io, and every price change is written to a Google Sheet as a new row. If you make reports for clients, there is an optional last step that shows the same sheet in Google Data Studio (it was called Looker Studio for a while). I got lost in it myself the first time, so every part is labelled.

Competitor website changes recorded in Google Sheets by changedetection.io, one row per price change

The parts, and the steps to join them

The one thing to know before starting: the Google Sheet is where the changes are recorded. changedetection.io sends each change to the sheet, and that is all you need. Data Studio is optional: it cannot receive anything itself, it only reads the sheet and shows it as a report.

The parts: the shop, changedetection.io and a Google Sheet, with Data Studio as an optional fourth part

These are the steps, in the order we'll do them:

  1. changedetection.io: import the competitor's product pages.
  2. Google Sheets: make a sheet with a header row.
  3. Google Sheets: add a small script that receives each price change and writes a row.
  4. changedetection.io: point the notification at that script, and set it to Plain Text.
  5. Test: a price changes, a row appears.
  6. Data Studio (optional): connect the sheet and build a report.

The short version: changedetection.io watches the prices, and a posts:// notification writes each change to a Google Sheet as a new row. Set it up once and every later price change is recorded by itself. Data Studio on top is optional.

For the competitor I'm using a small stand-in coffee shop, www.my-competitor.com, so I can change its prices on purpose and you can see real detections. Use your client's real competitor pages instead.

Step 1: import the competitor product pages (changedetection.io)

Click Import in the left bar and stay on the URL List tab. Under "Processor" choose Re-stock & Price detection for pages with a SINGLE product, so the price is read from each page. Then paste the product pages, one per line, each followed by a space and a group name. I used "Competitor prices":

http://www.my-competitor.com/products/espresso-machine-barista-pro.html Competitor prices
http://www.my-competitor.com/products/burr-coffee-grinder-g2.html Competitor prices
http://www.my-competitor.com/products/pour-over-kettle-gooseneck.html Competitor prices

changedetection.io Import page with Re-stock and Price detection chosen and competitor product pages listed with a group name

Click Import. The group name puts all the pages in one group, so the notification is set once on the group instead of on every page. (Or import through the API, the MCP server or an .XLSX file; the result is the same.)

A few moments later the pages are in your list with the price found on each:

changedetection.io list of imported competitor product pages, with the price found on each page

On the subscription that is all there is to do on our side: nothing to install and no server to run, just log in and import.

Step 2: make the Google Sheet

Now over to Google. Create a new Google Sheet (I called mine "changedetection.io changes") and type these six headers into the first row:

timestamp, title, url, price, previous_price, in_stock

This sheet is where the changes are recorded.

Step 3: add the script that receives price changes (Google Sheets)

In the sheet, open Extensions, then Apps Script.

Google Sheets with red circles on the Extensions menu and on Apps Script

Delete what is in the editor, paste this, and save:

/** @OnlyCurrentDoc */
function doPost(e) {
  const d = JSON.parse(e.postData.contents);
  SpreadsheetApp.getActive().getSheets()[0].appendRow([
    new Date(), d.title, d.url, Number(d.price), Number(d.previous_price), d.in_stock
  ]);
  return ContentService.createTextOutput('ok');
}

Google Apps Script editor with the script that writes each changedetection.io price change to Google Sheets as a row

In plain words: when something is sent to this script, it adds one row to the sheet. The line in the red box decides what goes in each column, left to right. The first line, @OnlyCurrentDoc, means the script may only touch this one spreadsheet.

Now make it reachable. Still in the Apps Script editor, look at the top right corner: click the blue Deploy button, then New deployment.

Google Apps Script editor with a red circle on the Deploy button at the top right and New deployment in its menu

A "New deployment" box opens. Click the cog next to "Select type" and choose Web app, set "Who has access" to Anyone, and click Deploy. Google asks you to authorize access the first time; that is you allowing your own script to write to your sheet.

Google Apps Script New deployment box: type Web app, who has access Anyone, then Deploy

Google then shows a Web app URL. Copy it, this is the address changedetection.io will send to.

Google Apps Script deployment result with a red circle on Copy for the Web app URL

Treat that address like a password: anyone who has it can add rows to your sheet.

Alternatively: one row per product, kept up to date

The script above keeps a log: every price change is a new row. If you would rather have one row per product that always shows the latest price, use this version instead. It looks down column B for the same title; if it finds it, that row is updated, and if not, a new row is added:

/** @OnlyCurrentDoc */
function doPost(e) {
  const d = JSON.parse(e.postData.contents);
  const sheet = SpreadsheetApp.getActive().getSheets()[0];
  const row = [new Date(), d.title, d.url, Number(d.price), Number(d.previous_price), d.in_stock];
  const titles = sheet.getRange('B:B').getValues().map(r => r[0]);
  const found = titles.indexOf(d.title);
  if (found > 0) {
    sheet.getRange(found + 1, 1, 1, row.length).setValues([row]);
  } else {
    sheet.appendRow(row);
  }
  return ContentService.createTextOutput('ok');
}

Google Apps Script that updates the existing Google Sheets row when the title in column B matches, instead of adding a new row

Everything else in this tutorial stays the same. Pick one of the two; the rest of the screenshots use the first one, the log.

Step 4: point the notification at the sheet (changedetection.io)

Back in changedetection.io, open Watch Groups, click Edit next to "Competitor prices", then the Notifications tab.

First, under "Send this group's notifications", choose As well as the watch's own. That makes the group send its own notification, with the address, body and format you set on this page kept together.

In "Notification URL List", paste the Web app URL and change the https:// at the front to posts://. That tells changedetection.io to send the notification as a web request to that address:

posts://script.google.com/macros/s/YOUR-DEPLOYMENT-ID/exec

Then open Customise notifications and paste this into "Notification Body":

{
  "title": {{ watch_title|tojson }},
  "url": {{ watch_url|tojson }},
  "price": {{ restock.price|tojson }},
  "previous_price": {{ restock.previous_price|tojson }},
  "in_stock": {{ restock.in_stock|tojson }}
}

Last thing on this page, and don't skip it: set "Notification format" to Plain Text, then click Save.

changedetection.io group notification settings: sent as well as the watch's own, with the posts:// Web app URL, the JSON body and Plain Text

I tried it both ways. With the standard format the body is sent as HTML, changedetection.io says the notification was sent, and no row turns up in the sheet. With Plain Text the rows arrive.

How the notification body lines up with the sheet

This is the part that joins everything, so here it is in one picture. Each name in the notification body ("title", "price"...) is picked up by the same name in the script (d.title, d.price...), and the order inside appendRow is the order of the columns in the sheet.

How the changedetection.io notification body lines up with the Apps Script appendRow line and the Google Sheets columns

Want another column? Add it in all three places: a new line in the body, the matching d.name in the script, and a header in the sheet. After changing the script, deploy it again (Deploy, Manage deployments, edit, new version).

Step 5: test it

Nothing is sent until a price really changes, and pages are rechecked on a timer, so a change is picked up at the next check (you choose how often pages are checked). I dropped a few prices in my stand-in shop and clicked "Recheck all". Each change arrived in the sheet as its own row:

Google Sheets with competitor price changes sent by changedetection.io, one row per price change

The G2 grinder went from $189 to $169, and later up to $175, so it is there twice. That is the idea: the sheet is a log of every change.

Google having a slow minute? The row isn't lost: an alert that can't be delivered is tried again.

And that's it, the recording part is done. It is an ordinary Google Sheet, so share it with a client, sort it, add a column that works out the difference between price and previous_price, or download it.

Step 6 (optional): show it in Data Studio

This step is optional. Your competitor changes are already being recorded in the sheet, and you can stop here. Carry on only if you want the same data as a report, for example one you share with a client.

In Data Studio, create a report (or open one you already have) and click Add data. Choose Google Sheets, authorize it if asked, pick your spreadsheet and click Add.

Data Studio Add data to report screen with a red circle on the Google Sheets connector

Your columns appear on the right as fields, with the right types already (a date, numbers, text):

Data Studio report editor showing the Google Sheets columns as fields: title, price, previous price, timestamp

Now the part people like to look at: a chart of each product's price before and now. Click Add a chart, choose a Bar chart and click on the page to place it.

Data Studio Add a chart menu with a red circle on the bar chart

With the chart selected, look under Metric on the right. Drag previous_price and price there from the list of fields, and remove "Record Count". Then click the small icon to the left of each one and give it a name people understand: "Price before" and "Price now".

Data Studio bar chart setup with the metrics named Price before and Price now, two bars for each competitor product

That gives two bars side by side for every product, so a price that went down or up is easy to spot:

Google Data Studio bar chart of competitor prices before and now for each product, read from Google Sheets

Use the one-row-per-product sheet for this chart (the "Alternatively" script in step 3). With the log version a product has several rows, and Data Studio would add all its prices together. On the log, leave "Record Count" in place instead: it is Data Studio's name for "how many rows", so the bars show how many times each product changed price.

From here it is ordinary Data Studio: add a table with title, price and previous_price, a filter for one competitor, your client's logo.

Data Studio reads the sheet again by itself from time to time, so new price changes turn up in the report without you doing anything.

What next

Google Sheets and Data Studio: questions and answers

Do I need Data Studio?

No. The Google Sheet records every change on its own. Data Studio is only for showing the sheet as a report.

Can changedetection.io send data straight to Google Data Studio?

No, and nothing can: Data Studio has nowhere to send data to. It reads from data sources such as Google Sheets or BigQuery. So changedetection.io sends each change to a Google Sheet and Data Studio reads the sheet.

I can't find "Extensions" in Data Studio. Where is Apps Script?

It is in Google Sheets, not in Data Studio. Open the spreadsheet, then Extensions, then Apps Script.

changedetection.io says the notification was sent, but no row appears

Check step 4: the group is set to "As well as the watch's own" and "Notification format" is Plain Text. Then check that the names in the notification body are spelled the same as in the script.

Is this the same as Looker Studio?

Yes. Google called it Looker Studio for a while and has gone back to the name Data Studio. The steps are the same.

Can I use this for website changes that are not prices?

Yes. On the Import page choose the other processor, "Webpage Text/HTML, JSON and PDF changes", and send other details in the body, for example {{ diff_added|tojson }} for the text that was added.