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.
1. Prepare the API key and spreadsheet
- In NowMetrix, open Settings → API and create a separate key labeled Google Sheets.
- Copy the complete key when it is shown. It cannot be displayed again later.
- Note the tracker ID for the website you want to export.
- Create a new Google Sheet, for example NowMetrix Export.
- 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:
- Open Project Settings using the gear icon.
- Under Script Properties, select Add script property.
- Add the following two properties:
| Property | Value |
|---|---|
NOWMETRIX_API_KEY |
Your key beginning with nm_ |
NOWMETRIX_TRACKER_ID |
The tracker ID to export |
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
- Name the project NowMetrix Google Sheets Export in the top-left corner.
- Save the Apps Script project using the disk icon or the keyboard shortcut.
- Select
syncNowMetrixDailyin the function menu in the editor toolbar. - Select Run next to the function menu.
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.
- Confirm that you created the Apps Script project and that the developer email is yours.
- Select Advanced on the warning screen.
- Continue to your named project. Google may label this link as unsafe because the private project is not verified.
- 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. |
@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
- Create or open a report in Looker Studio.
- Select Add data → Google Sheets.
- Select the spreadsheet and the Daily worksheet.
- Use the first row as headers and connect the data source.
- Confirm that
dateis a date and thatpageviewsandvisitsare 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 |
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
@OnlyCurrentDocin 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.
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. |