Clicks → Google Sheets overview
Pull advertiser click totals by date into Google Sheets. The Apps Script sample requires start_date and end_date (max 90 days), authenticates with X-Api-Key, and writes flat click rows to a Clicks tab.
Endpoint:
GET /api/v1/clicks
Clicks responses return flat objects under data (not nested JSON:API attributes). start_date and end_date are required; ranges cannot exceed 90 days.
Setup in Google Sheets
- Open a Google Sheet → Extensions → Apps Script.
-
Get your personal API key from
API key docs.
Prefer the
X-Api-Keyheader (these samples already do). -
In Apps Script, open Project Settings → Script properties
and add
HIENERGY_API_KEYwith your key value. - Paste the shared client library, then the resource import script below.
- Click Save, reload the Sheet, and run the import from the Hi Energy AI menu (or Run in the editor).
-
On first run, authorize the script when Google prompts for
UrlFetchApp/ external request permission.
2. Clicks import script
Paste this below the shared client, save the project, then run the import function (or use the Hi Energy AI custom menu after reloading the sheet).
/**
* Import click analytics into Google Sheets.
* Requires the shared Hi Energy client helpers in this Apps Script project.
*
* start_date and end_date are required. Maximum range is 90 days.
*/
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Hi Energy AI')
.addItem('Import clicks', 'importHiEnergyClicks')
.addToUi();
}
function importHiEnergyClicks() {
var START_DATE = isoDateDaysAgo_(30);
var END_DATE = isoDateToday_();
// Admins only: set a publisher id to scope clicks. Non-admins are scoped automatically.
var PUBLISHER_ID = '';
var page = 1;
var perPage = 100;
var allRows = [];
var maxPages = 50;
while (page <= maxPages) {
var payload = hiEnergyApiGet_('/api/v1/clicks', {
start_date: START_DATE,
end_date: END_DATE,
publisher_id: PUBLISHER_ID,
page: page,
per_page: perPage,
include_total: false
});
var records = Array.isArray(payload.data) ? payload.data : [];
if (!records.length) break;
records.forEach(function(row) {
var flat = {};
Object.keys(row).forEach(function(key) {
var value = row[key];
flat[key] = (value !== null && typeof value === 'object') ? JSON.stringify(value) : value;
});
allRows.push(flat);
});
if (records.length < perPage) break;
page += 1;
}
var count = writeObjectsToSheet_('Clicks', allRows, true);
SpreadsheetApp.getActiveSpreadsheet().toast('Imported ' + count + ' click rows', 'Hi Energy AI', 5);
}Useful query parameters
| Parameter | Purpose |
|---|---|
start_date |
Required ISO date (YYYY-MM-DD). Inclusive range start. |
end_date |
Required ISO date (YYYY-MM-DD). Inclusive range end. |
publisher_id |
Admins can scope to a publisher; other users are auto-scoped. |
page / per_page / limit |
Pagination controls for large click extracts. |
include_total |
Optional total count for reporting UIs. |
FAQ
Paste the shared Apps Script client and clicks importer, set HIENERGY_API_KEY, then run importHiEnergyClicks. It calls GET /api/v1/clicks with required start_date and end_date.
The Clicks API allows at most 90 days between start_date and end_date. Split larger history into multiple imports.
Yes. Non-admin users are scoped to their publisher. Admins may optionally pass publisher_id.
Yes. GET /api/v1/clicks requires both dates. The sample defaults to the last 30 days; adjust START_DATE and END_DATE before running.
Clicks responses return flat objects under data (not nested JSON:API attributes), so the importer writes those fields directly as spreadsheet columns.
Yes. This page publishes TechArticle, HowTo, FAQPage, BreadcrumbList, WebSite SearchAction, and related endpoint ItemList structured data for answer engines.