Build a Weekly Marketing Report
Build a weekly marketing report with the Hardal Analytics API and Python, using a fixed date range and reporting context.
Use the Analytics API to collect the same traffic summary each week. Explicit dates and timezone make the result easier to reproduce than a moving preset that includes the current day.
Choose the report definition
Start with a tenant-scoped API key and a tenant ID from Workspace Access. Decide whether the report includes all sources or one specific source.
For a traffic readout, request Overview scorecards for a completed period. Record the period, timezone, and source with the numbers. Add Acquisition as a separate section when you need conversion-credit analysis; do not relabel Overview session totals as campaign conversions.
Retrieve the period
The following Python example uses only the standard library. Set HARDAL_API_KEY, HARDAL_TENANT_ID, HARDAL_START_DATE, and HARDAL_END_DATE in your server environment. Dates use YYYY-MM-DD; HARDAL_SOURCE_ID is optional.
import json
import os
from datetime import date
from pathlib import Path
from urllib.parse import urlencode
from urllib.request import Request, urlopen
start = date.fromisoformat(os.environ["HARDAL_START_DATE"])
end = date.fromisoformat(os.environ["HARDAL_END_DATE"])
if end < start:
raise ValueError("End date must not precede start date")
params = {
"tenantId": os.environ["HARDAL_TENANT_ID"],
"timeframe": "custom",
"startDate": start.isoformat(),
"endDate": end.isoformat(),
"timezone": "Europe/Istanbul",
"interval": "day",
}
if os.environ.get("HARDAL_SOURCE_ID"):
params["sourceId"] = os.environ["HARDAL_SOURCE_ID"]
request = Request(
"https://api.hardal.ai/v1/reports/overview?" + urlencode(params),
headers={"Authorization": "Bearer " + os.environ["HARDAL_API_KEY"]},
)
with urlopen(request, timeout=60) as response:
result = json.load(response)
if result.get("success") is not True:
raise RuntimeError("The report request did not succeed")
snapshot = {"request": params, "report": result["data"]}
output = Path(f"hardal-overview-{start}-{end}.json")
output.write_text(json.dumps(snapshot, indent=2), encoding="utf-8")
print("Saved", output)
Turn the snapshot into a readout
Read report.scoreCards for the summary and the returned range for its effective scope. Present the main traffic change, relevant breakdowns, and the next investigation. Preserve missing values rather than replacing them with zero.
Run the script in your own environment or scheduler. It does not create a scheduled report or send messages through Hardal. Handle API errors and Retry-After before adding unattended execution.
For campaign rows, use Export Campaign Reports to CSV. See Use the Analytics API for authentication and response handling.