Session data
Session data holds counters, the latest events, top donations and goals, in the format of StreamElements. A widget gets it in onWidgetLoad and again, updated, in onSessionUpdate after every alert event, every change of a tip variable, and when a new stream starts.
let session = {};
window.addEventListener('onWidgetLoad', (obj) => {
session = obj.detail.session.data;
render();
});
window.addEventListener('onSessionUpdate', (obj) => {
session = obj.detail.session;
render();
});
function render() {
document.getElementById('followers').textContent = session['follower-session'].count;
}Every key below always exists, with zeros and empty texts until something happens. Values are objects ({ count }, { amount }, { name, amount }, …) or lists.
Periods
| Suffix | Counts events |
|---|---|
-session |
since the latest stream started (before your first stream: in the last 24 hours) |
-week |
in the last 7 days |
-month |
in the last 30 days |
-total |
that Streamed keeps (see below) |
A stream starts when the first of your channels goes live; if it comes back within 10 minutes, the same stream goes on. When a new one starts, the -session values start again from zero.
The counts are made from the events Streamed keeps when the widget loads (the latest 200, and more of the current stream if there are more; by default the server keeps 100 of each kind), plus the events that come in while it is open. So -total is not an all-time number, and a week-old event is not taken off -week until the widget reloads. For numbers that must be exact over time, use variables or the store.
The tip values that are variables are the exception: they are not counted from events, and they use calendar weeks and months.
Latest events
| Key | Value |
|---|---|
follower-latest |
{ name } |
subscriber-latest |
{ name, amount, tier, message, sender, gifted } |
subscriber-new-latest |
{ name, amount, message }: the latest first-month subscriber |
subscriber-resub-latest |
{ name, amount, message }: the latest resub |
subscriber-gifted-latest |
{ name, amount }: the latest gifter |
cheer-latest |
{ name, amount, message } |
raid-latest |
{ name, amount } |
tip-latest |
{ name, amount, message } (Ko-fi) |
sponsor-latest |
{ name, amount } (YouTube membership) |
superchat-latest |
{ name, amount } (YouTube Super Chat) |
YouTube's new subscribers are subscriber events, so on YouTube the subscriber-* keys count them.
Counters
| Keys | Value |
|---|---|
follower-session, follower-week, follower-month, follower-total |
{ count } of follows |
subscriber-session, subscriber-week, subscriber-month, subscriber-total |
{ count } of subscription events (a gift bundle and each of its gifts count separately) |
subscriber-new-session, subscriber-resub-session |
{ count } this stream: with amount 1, and with more (a gift bundle counts as a resub here) |
sponsor-session, sponsor-week, sponsor-month, sponsor-total |
{ count } of memberships |
cheer-session, cheer-week, cheer-month, cheer-total |
{ amount } of bits |
tip-session, tip-week, tip-month, tip-total |
{ amount } of money (see tip variables) |
superchat-session, superchat-week, superchat-month, superchat-total |
{ count } of Super Chats (not money) |
cheer-count, tip-count, superchat-count |
{ count } of events, in all the kept history |
Amounts of different currencies are added up as plain numbers.
Goals
tip-goal is { amount }, the value of the tip_goal variable, which you set on the dashboard. The other goals (follower-goal, subscriber-goal, cheer-goal, sponsor-goal, superchat-goal) are always { amount: 0 }: use a field or a variable for them.
const goal = session['tip-goal'].amount;
const raised = session['tip-month'].amount;
const percent = goal > 0 ? Math.min(100, (raised / goal) * 100) : 0;Top donations
The biggest single event (-top-donation) and the viewer with the biggest sum (-top-donator), each { name, amount }, for tip, cheer and superchat, and for the periods session, weekly, monthly and alltime:
tip-session-top-donation, tip-session-top-donator, tip-weekly-top-donation, tip-weekly-top-donator, tip-monthly-top-donation, tip-monthly-top-donator, tip-alltime-top-donation, tip-alltime-top-donator, cheer-session-top-donation, cheer-session-top-donator, cheer-weekly-top-donation, cheer-weekly-top-donator, cheer-monthly-top-donation, cheer-monthly-top-donator, cheer-alltime-top-donation, cheer-alltime-top-donator, superchat-session-top-donation, superchat-session-top-donator, superchat-weekly-top-donation, superchat-weekly-top-donator, superchat-monthly-top-donation, superchat-monthly-top-donator, superchat-alltime-top-donation, superchat-alltime-top-donator
They are counted from the kept events, like the counters (tips here are not the tip variables).
Recent lists
Up to 25 events each, newest first, as { name, amount, type, createdAt } (subscriptions also tier):
follower-recent, subscriber-recent, cheer-recent, raid-recent, tip-recent, sponsor-recent, superchat-recent
onWidgetLoad also has recents: the same for all kinds together. Neither has platform or the gift flags (gifted, bulkGifted, isCommunityGift).
Keys that stay empty
These exist so StreamElements widgets do not break, but nothing fills them in Streamed:
subscriber-alltime-gifter, subscriber-points, host-latest, host-recent, sponsor-gifted-latest, merch-latest, merch-recent, merch-goal-items, merch-goal-orders, merch-goal-total, purchase-latest, channel-points-latest, hypetrain-latest, hypetrain-level-goal, hypetrain-level-progress, hypetrain-total, hypetrain-latest-top-contributors, charityCampaignDonation-latest, charityCampaignDonation-recent, charityCampaignDonation-count, cheerPurchase-latest, cheerPurchase-recent, cheerPurchase-count, and the -top-donation / -top-donator keys of charityCampaignDonation and cheerPurchase: charityCampaignDonation-session-top-donation, charityCampaignDonation-session-top-donator, charityCampaignDonation-weekly-top-donation, charityCampaignDonation-weekly-top-donator, charityCampaignDonation-monthly-top-donation, charityCampaignDonation-monthly-top-donator, charityCampaignDonation-alltime-top-donation, charityCampaignDonation-alltime-top-donator, cheerPurchase-session-top-donation, cheerPurchase-session-top-donator, cheerPurchase-weekly-top-donation, cheerPurchase-weekly-top-donator, cheerPurchase-monthly-top-donation, cheerPurchase-monthly-top-donator, cheerPurchase-alltime-top-donation, cheerPurchase-alltime-top-donator.