Users and their banners
A report of every user of your white label with the number of banners that each user made, in total and in this month.
This report lists every user of your white label with the number of banners that each user made: in total, and in this month. It calls get-users for the list of users, and then get-user-banners once for each user. It needs no new action of the API.
What the report counts
get-user-banners with type=all lists the
published, active single banners and banner sets of a user. The
report counts a single banner as 1, and a banner set as the number
of banners in it, from numberOfBanners. This is Banners
total.
Created this month adds up the same numbers, but only for the items
whose dateCreated is in the current calendar month, in
UTC. A banner set counts with all its banners in the month when the
set was created.
The report and the Enterprise admin
The Users page of the Enterprise admin shows similar columns. This table compares them.
| Admin column | In this report |
|---|---|
| Created total | Banners total. It is the same number: both count the published, active banners, and each banner of a banner set. |
| Created this month | Created this month. The admin filters this column by date only when your white label pays per banner. It then counts from your last billing date. For the other white labels, the admin shows the total again, so the two columns often have the same number. This report always counts the calendar month, by the date when an item was created. |
| Impressions, group and user type | Not in this report, because the API does not give them. |
What the report changes
Each get-user-banners call signs in that user for that one request. This sign-in ends no other session of the user, so an open editor keeps working.
The report creates no user, because every identifier comes from get-users. get-users signs in nobody. The report changes no banner.
The call budget
This demo site accepts at most 300 calls for
each client id and 600 calls for each address in
15 minutes. The report makes one
get-users call for each 100 users, and
one get-user-banners call for each user. It makes
4 calls at a time.
After 250 calls, the report stops and keeps the rows that it counted. Wait 15 minutes, then select Continue. The report goes on from the next user that it did not count. If the demo refuses a call with HTTP 429, the report also stops, and Continue works the same way.
These limits belong to this demo site. Your own server calls the API directly, as in the Node example below.
Run the report
Enter your credentials, then select Run the report. The table fills in as the answers come, with the most banners first. Stop ends the report after the calls that already started. Use as test user puts an identifier into the forms of this site. Download CSV saves the table as a file.
The report runs in your browser. It needs JavaScript.
The same report in Node
This script makes the same calls from your server, one at a time. It
reads the secret key from the environment variable
BANNERSNACK_SECRET_KEY. Replace YOUR_CLIENT_ID
with your client id. It stops at the first error.
import { createHmac } from 'node:crypto';
const CLIENT_ID = 'YOUR_CLIENT_ID';
const API_URL = "https://enterprise.bannersnack.com/wapi/2.0/";
async function callApi(action, values) {
const params = { ...values, action, client_id: CLIENT_ID };
params.t = String(Math.floor(Date.now() / 1000));
const data = Object.keys(params).sort().map(key => key + params[key]).join('');
params.signature = createHmac('sha1', process.env.BANNERSNACK_SECRET_KEY).update(data).digest('hex');
const response = await fetch(API_URL + '?' + new URLSearchParams(params));
const answer = await response.json();
if (answer.code !== 200) {
throw new Error(action + ' failed: ' + JSON.stringify(answer));
}
return answer.data;
}
function countBanners(items, now) {
const start = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1) / 1000;
const end = Date.UTC(now.getUTCFullYear(), now.getUTCMonth() + 1, 1) / 1000;
let total = 0;
let thisMonth = 0;
for (const item of items) {
const banners = item.type === 'bannerset' ? Number(item.numberOfBanners) : 1;
total += banners;
if (item.dateCreated >= start && item.dateCreated < end) {
thisMonth += banners;
}
}
return { total, thisMonth };
}
const now = new Date();
const rows = [];
for (let page = 1; ; page++) {
const list = await callApi('get-users', { page_number: String(page), per_page: '100' });
for (const user of list.users) {
const items = await callApi('get-user-banners', { identifier: user.identifier, type: 'all' });
const { total, thisMonth } = countBanners(items, now);
rows.push({ identifier: user.identifier, name: user.name, status: user.status, total, thisMonth });
}
if (list.users.length === 0 || list.page_number * list.per_page >= list.total) {
break;
}
}
rows.sort((a, b) => b.total - a.total);
console.table(rows);