SoccersAPISoccersAPIWidgets V2

Events for developers

The browser events the widget sends to your page, so your site can react to what visitors open and choose.

The widget can tell the page it runs on what the visitor is doing. Your developer can listen for these events to update the page title and description, track views in your analytics, or take over navigation.

These events exist only with the script installation of paid plans. An iframe cannot send events to your page.

EventSent onWhen
sapi:entitywindowA match, team, competition or player view loads. Needs Broadcast entity metadata.
sapi:navigatewindowThe widget is about to navigate to one of your Dynamic Pages.
theme-changethe <ls-soccersapi> elementThe visitor switches between light and dark.
ls:timezone-changedwindowThe visitor changes the time zone in the widget settings.

None of these events says which widget sent it. If your page has several widgets, keep that in mind.

sapi:entity: the item being viewed

Plans

Sent when a match, team, competition or player view loads its data, and again when its season changes. It needs Broadcast entity metadata on, in the Dynamic Pages section, on a domain with the Dynamic Pages add-on.

window.addEventListener('sapi:entity', (event) => {
  const item = event.detail;
  if (item.kind === 'match') {
    document.title = `${item.home} vs ${item.away} | My site`;
  }
});

event.detail.kind is match, team, league or player. The other fields depend on it:

kindFields
matchid, name, home, away, home_id, away_id, league, league_id, season_id, date, status, status_name, minute, score
teamid, name, team_name, country, league, league_id, season_id, logo
leagueid, name, league_name, country, season_id, logo
playerid, name, player_name, country, team, team_id, season_id, logo
  • A live match sends the event again as its data changes. Write your handler so it can run many times.
  • Floating cards do not send it; only the main view does.
  • The widget itself never changes your page title or meta tags.

Search engines

Titles set from JavaScript are read by some search engines and ignored by others. For the most reliable result, render the title and description on your server from the same data: the number in the page address identifies the item.

sapi:navigate: before a Dynamic Pages navigation

Sent before the widget moves the visitor to one of your pages in Dynamic Pages mode, when the navigation does not come from a plain link click. The event can be cancelled: call event.preventDefault(), or set event.detail.handled = true, and the widget does not navigate. Your application then handles the route itself.

window.addEventListener('sapi:navigate', (event) => {
  const { href, action } = event.detail;
  if (myRouter.canHandle(href)) {
    event.preventDefault();
    action === 'replace' ? myRouter.replace(href) : myRouter.push(href);
  }
});
FieldWhat it holds
hrefThe address of the page, for example /en/matches/{name}/{id}.
entity, paramsThe kind of item and its identifiers.
actionpush, replace or back.
target, relThe link target and rel set in the configurator.
mode, source, state, options, deltaDetails of the navigation request.

theme-change and ls:timezone-changed

  • theme-change is sent on the <ls-soccersapi> element and bubbles. event.detail.theme is light or dark.
  • ls:timezone-changed is sent on window. event.detail.timezone is the new time zone, such as Europe/Madrid.
document.querySelector('ls-soccersapi')
  .addEventListener('theme-change', (event) => {
    document.documentElement.dataset.theme = event.detail.theme;
  });

On this page