Export · Google Sheets

Keep NowMetrix metrics in Google Sheets

Use Google Apps Script to fetch daily NowMetrix data securely, refresh the spreadsheet on a schedule, and make it available for calculations, sharing, or Looker Studio reports.

How the connection works

The spreadsheet acts as a small, customer-controlled data bridge:

NowMetrix REST API → Google Apps Script → Google Sheet → optional Looker Studio report

The data is not imported into Google Analytics. Apps Script requests the selected NowMetrix endpoint with your API key and writes the returned rows into the spreadsheet. Looker Studio can then use that worksheet as a separate data source.

This setup is a good fit for hourly or daily reporting. Google Sheets and Looker Studio cache data, so use the NowMetrix dashboard for second-by-second newsroom monitoring.

1. Prepare the API key and spreadsheet

  1. In NowMetrix, open Settings → API and create a separate key labeled Google Sheets.
  2. Copy the complete key when it is shown. It cannot be displayed again later.
  3. Note the tracker ID for the website you want to export.
  4. Create a new Google Sheet, for example NowMetrix Export.
  5. Set the spreadsheet time zone to the same time zone as the NowMetrix tracker.

The example below exports the last 30 daily rows from /v1/overview. Each row contains the date, tracker, tracker time zone, pageviews, and visits.

2. Store the API key in Script Properties

In the Google Sheet, select Extensions → Apps Script. Then:

  1. Open Project Settings using the gear icon.
  2. Under Script Properties, select Add script property.
  3. Add the following two properties:
Property Value
NOWMETRIX_API_KEY Your key beginning with nm_
NOWMETRIX_TRACKER_ID The tracker ID to export
Never put the API key in a spreadsheet cell, a report parameter, the script source, a URL, or a log message. Script Properties keep it out of the worksheet, but people with edit access to the Apps Script project must still be trusted.

3. Add the export script

Replace the contents of Code.gs with this script. It checks the configuration, limits spreadsheet access to the current document, handles API errors, and only replaces the worksheet after a successful response.

/**
 * @OnlyCurrentDoc
 */

const NOWMETRIX_BASE_URL = 'https://api.nowmetrix.com';

function fetchNowMetrix(path) {
  const properties = PropertiesService.getScriptProperties();
  const apiKey = properties.getProperty('NOWMETRIX_API_KEY');
  const trackerId = properties.getProperty('NOWMETRIX_TRACKER_ID');

  if (!apiKey || !trackerId) {
    throw new Error('NOWMETRIX_API_KEY or NOWMETRIX_TRACKER_ID is missing.');
  }

  const separator = path.includes('?') ? '&' : '?';
  const url = NOWMETRIX_BASE_URL
    + path
    + separator
    + 'site=' + encodeURIComponent(trackerId);

  const response = UrlFetchApp.fetch(url, {
    method: 'get',
    headers: {
      Authorization: 'Bearer ' + apiKey,
      Accept: 'application/json'
    },
    muteHttpExceptions: true
  });

  const status = response.getResponseCode();
  const body = response.getContentText();

  if (status < 200 || status >= 300) {
    throw new Error('NowMetrix API returned HTTP ' + status + ': ' + body);
  }

  return JSON.parse(body);
}

function toSheetDate(value) {
  const parts = value.split('-').map(Number);
  return new Date(parts[0], parts[1] - 1, parts[2]);
}

function syncNowMetrixDaily() {
  const result = fetchNowMetrix('/v1/overview?days=30');
  const rows = result.daily.map(day => [
    toSheetDate(day.date),
    result.site,
    result.timezone,
    day.pageviews,
    day.visits
  ]);

  const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = spreadsheet.getSheetByName('Daily')
    || spreadsheet.insertSheet('Daily');
  const values = [
    ['date', 'tracker', 'timezone', 'pageviews', 'visits'],
    ...rows
  ];

  sheet.clearContents();
  sheet.getRange(1, 1, values.length, values[0].length).setValues(values);
  sheet.setFrozenRows(1);
  sheet.getRange(1, 1, 1, values[0].length).setFontWeight('bold');

  if (rows.length > 0) {
    sheet.getRange(2, 1, rows.length, 1).setNumberFormat('yyyy-mm-dd');
    sheet.getRange(2, 4, rows.length, 2).setNumberFormat('#,##0');
  }

  sheet.autoResizeColumns(1, values[0].length);
}

Do not replace NOWMETRIX_API_KEY with the actual key in the source. The script reads it from Script Properties at runtime. Keep @OnlyCurrentDoc at the top: it tells Google to request access to this spreadsheet instead of all spreadsheets in your account.

4. Save and run the script once

  1. Name the project NowMetrix Google Sheets Export in the top-left corner.
  2. Save the Apps Script project using the disk icon or the keyboard shortcut.
  3. Select syncNowMetrixDaily in the function menu in the editor toolbar.
  4. Select Run next to the function menu.
Do not select Deploy. This export is not a web app, executable API, add-on, or library and does not require any deployment. Run the function directly in the editor.

5. Authorize your own Apps Script project

Google asks for permission the first time the script runs. Select Review permissions and choose the Google account that owns the spreadsheet.

A warning such as Google hasn't verified this app is expected for a private, self-created Apps Script project. The developer email shown by Google should be your own Google account. The project is not a NowMetrix Google app and does not give NowMetrix access to your Google account.

  1. Confirm that you created the Apps Script project and that the developer email is yours.
  2. Select Advanced on the warning screen.
  3. Continue to your named project. Google may label this link as unsafe because the private project is not verified.
  4. Review the requested permissions and select Allow or Continue.
Permission Why it is needed
Access to the current spreadsheet Create or update the Daily worksheet in this Google Sheet.
Connect to an external service Send an HTTPS request to https://api.nowmetrix.com.
Stop if the developer email is not yours, you did not create the project, or the code differs from the example. If Google requests access to all your spreadsheets, cancel, confirm that @OnlyCurrentDoc is at the very top of Code.gs, save, and run the function again.

If you already approved broader spreadsheet access, remove the project under Google Account → Security → Connections to third-party apps and services, then run the saved script again to request the reduced permissions.

Google documents this authorization flow and the @OnlyCurrentDoc restriction in its Apps Script authorization guide.

6. Verify the first export

After authorization, Apps Script continues the run. Wait for Execution completed in the execution log, return to the spreadsheet, and open the new Daily worksheet. The result should look similar to this:

date tracker timezone pageviews visits
2026-08-22 TRACKER_ID Europe/Zurich 81,240 53,210
2026-08-23 TRACKER_ID Europe/Zurich 77,480 50,195

7. Schedule automatic updates

In Apps Script, open Triggers using the clock icon and add a trigger:

Function syncNowMetrixDaily
Deployment Head
Event source Time-driven
Frequency Every hour, or less often for a daily report

The trigger runs under the Google account that created it. Keep that account active and review Apps Script failure notifications. Avoid unnecessarily frequent requests: the NowMetrix public API currently allows 20 requests per minute per tracker, shared across keys and users.

The example replaces the rolling 30-day table on every successful run. This prevents duplicate dates and keeps the sheet compact.

8. Use the worksheet in Looker Studio

  1. Create or open a report in Looker Studio.
  2. Select Add data → Google Sheets.
  3. Select the spreadsheet and the Daily worksheet.
  4. Use the first row as headers and connect the data source.
  5. Confirm that date is a date and that pageviews and visits are numeric metrics.

You can now build time-series charts, scorecards, tables, and calculated fields such as pageviews / visits. Looker Studio reads this as a separate data source; it does not turn NowMetrix values into Google Analytics events.

Google documents the remaining report settings in its Google Sheets connector guide.

Export other NowMetrix data

Use case Endpoint example Recommended sheet behavior
Daily Pageviews and Visits /v1/overview?days=30 Replace or update rows by tracker and date
Yesterday's top pages /v1/recap?preset=yesterday&limit=100 Append once per day or replace the current result
Current live snapshot /v1/realtime Append with the response timestamp when building a trend
Current traffic sources /v1/sources Append with the response timestamp or replace the current snapshot
A Recap such as preset=last30 contains totals for the complete rolling range. Do not append and add those values every day. For additive article history, export a completed period such as yesterday and store the range with every row.

Security and sharing checklist

  • Use a separate NowMetrix API key for the export and grant only the required tracker access.
  • Store the key only in Script Properties or another server-side secret store.
  • Keep @OnlyCurrentDoc in the script to restrict Google Sheets access to this document.
  • Never include the key in cells, formulas, report parameters, URLs, screenshots, or logs.
  • Limit edit access to the Apps Script project. Editors must be treated as trusted users.
  • Authorize the script only when Google shows your own account as the developer.
  • Use a separate customer-owned spreadsheet for each NowMetrix account.
  • Review both Google Sheet and Looker Studio sharing settings before publishing a report.
  • Revoke the API key immediately if the sheet, script, or Google account may be compromised.
API access follows the NowMetrix user's permitted trackers. Removing that access or revoking the key stops future exports but does not delete data that has already been copied to Google.

Troubleshooting

Problem What to check
HTTP 401 The API key is missing, incomplete, invalid, or revoked.
HTTP 403 The API key does not have access to the configured tracker.
HTTP 429 The tracker-wide API rate limit has been exceeded. Reduce the trigger frequency.
HTTP 503 The analytics backend is temporarily unavailable. Keep the existing sheet data and retry later.
No Daily worksheet Run syncNowMetrixDaily manually and inspect the Apps Script execution details.
Google says the app is not verified This is expected for your private script. Continue only when you created the project and Google shows your own developer email.
Google requests access to all spreadsheets Cancel, add @OnlyCurrentDoc at the top of Code.gs, save, and run the function again.
Dates look incorrect Match the Google Sheet time zone to the tracker time zone returned by the API.