A lightweight, production-ready Go service that periodically polls the Google
AdSense Management API v2 and
forwards real-time events to Telesink using the official
telesink-go SDK.
Perfect for getting instant notifications about alerts, policy issues, site status changes, payments, and daily earnings — all delivered cleanly into your Telesink dashboard.
| Event Name | Description | Emoji | Key Properties |
|---|---|---|---|
AdSense alert |
Policy violations, payment holds, crawler errors | 🚨 | severity, type, message |
AdSense policy issue |
Active policy or regulatory issues | action, site |
|
AdSense site status |
Site approval/deactivation changes | 📍 | domain, state |
AdSense payment |
New payments and balance updates | 💰 | amount, currency, date |
AdSense daily earnings |
Yesterday's earnings + key metrics | 📊 | earnings, currency, clicks, impressions, page_views, date |
-
Clone the repo:
git clone https://github.com/telesink/telesink-adsense.git cd telesink-adsense -
Edit
.envwith your credentials:cp .env.example .env
-
Start the service
docker compose up -d
The poller will start immediately and continue running.
-
Go to https://www.google.com/adsense and sign in.
-
In the left sidebar, click Account → Settings → Account information.
-
Your Publisher ID will be displayed (looks like
pub-1234567890123456). -
Prepend
accounts/to it → this becomes yourADSENSE_ACCOUNT_ID.Example:
Publisher ID:pub-1234567890123456
→ADSENSE_ACCOUNT_ID=accounts/pub-1234567890123456
- Go to the Google Cloud Console
- Click Select a project → New Project.
- Give it a name (e.g.
telesink-adsense-integration) and click Create. - Once the project is selected, go to APIs & Services → Library.
- Search for "AdSense Management API" and click Enable.
This step is mandatory for long-lived tokens.
-
Go to APIs & Services → OAuth consent screen (or Google Auth Platform in the left sidebar).
-
You should land on the Audience tab.
-
Set User type to External (if not already selected).
-
At the top, click Publish app → Confirm.
Your app is now in In production status. The refresh token you generate next will be long-lived (no 7-day expiration).
Note about user cap: You may see a "100 user cap". This only applies to unapproved sensitive scopes. The AdSense scope we use is pre-approved, so this limit does not affect normal usage.
-
Go to APIs & Services → Credentials.
-
Click + Create Credentials → OAuth client ID.
-
Select Application type → Web application.
-
Give it a name (e.g.
Telesink AdSense). -
Under Authorized redirect URIs, click + Add URI and enter exactly this (copy-paste):
https://developers.google.com/oauthplaygroundImportant: No trailing slash, no
www, must be https. -
Click Create.
-
Copy the Client ID (
GOOGLE_CLIENT_ID) and Client Secret (GOOGLE_CLIENT_SECRET).⚠️ Wait 5–10 minutes after creating or editing the OAuth client ID before continuing. Google takes time to propagate changes. Trying too early is the #1 cause ofredirect_uri_mismatcherrors.
-
Open the Google OAuth 2.0 Playground.
-
Click the gear icon (⚙️) in the top-right corner.
-
Check the box Use your own OAuth credentials.
-
Paste your Client ID and Client Secret from step 3.
-
In Step 1 — Select & authorize APIs, paste this exact scope:
https://www.googleapis.com/auth/adsense.readonly -
Click Authorize APIs.
-
Sign in with the Google account that owns your AdSense account and grant the requested permissions.
-
After authorization succeeds, click Exchange authorization code for tokens.
-
Copy the refresh_token value (it is a long string starting with
1//or similar).This is your
GOOGLE_REFRESH_TOKEN.Important notes
- The refresh token never expires unless you revoke access or change your Google password.
- Keep
GOOGLE_CLIENT_SECRETandGOOGLE_REFRESH_TOKENprivate. - If you ever get an
invalid_granterror later, simply repeat step 4 to generate a fresh refresh token.
The application persists deduplication state in state.json. This file is
mounted as a Docker volume so events are not repeated on restarts. You can
safely delete state.json to reset all deduplication if needed.
Install dependencies:
go mod tidyRun locally:
go run .Build standalone binary:
CGO_ENABLED=0 GOOS=linux go build -o telesink-adsense .MIT (see LICENSE.md).