PlaygentDocs

DevelopersEmbed reference

Embed reference

Everything the embed script understands: options on the game's element, the JavaScript API, the events your page can listen to, and what to allow in a Content-Security-Policy.

The code

HTML
<div class="playgent" data-id="pg_7hk2qp0azx" style="min-height:640px"></div>
<script async src="https://play.playgent.com/embed/v1.js"></script>

The script finds every element with class="playgent" (or a data-playgent attribute) and puts the game there. It also finds elements your page adds later, so single-page apps need nothing extra. One script serves any number of games.

Options

Add these attributes to the game's element. Look, features and puzzles come from Studio, not from the code: change them there and update the game.

AttributeWhat it does
data-idRequired. The game's id: pg_ and 6 to 32 letters or digits. With a wrong id the space stays empty and the browser console says why.
data-titleThe game's name for screen readers, and the name on the Play card. Defaults to Game. Set it to the game's name.
data-skip-cover="true"Opens straight on the puzzle, without the cover.
data-start="click"Shows a light card with the name and a Play button. The game loads only when the button is pressed, then opens on the puzzle.
data-play-textThe Play card's button text. Defaults to Play.
data-max-widthThe widest the game gets. Defaults to 560px. Any CSS length.
data-heightThe space kept before the game sizes itself, in pixels. Defaults to 640. Change the inline min-height to match.
data-levelThe level the game opens on, such as hard, for games with levels. Overrides the level set in Studio.
data-dateA day as YYYYMMDD. A Daily game plays that day's puzzle.
data-streamA placement label, such as homepage or articles: lowercase letters, digits and hyphens, up to 40. Added to every page event as stream.
data-datalayerAlso sends events to Google Analytics 4 through window.dataLayer. See Google Analytics.

Try the options with the code builder.

Sizing

  • The game is as wide as its element, up to data-max-width, and centered.
  • Its height follows the game, between 200 and 4,000 px. There is no scrollbar inside the game.
  • It loads when it comes within 600 px of the screen.
  • The frame allows full screen, sharing and copying to the clipboard.

JavaScript API

Once the script loads, window.Playgent has:

JavaScript
Playgent.on('complete', (data, type) => { /* one event type */ })
Playgent.on('*', (data, type) => { /* every event */ })
Playgent.off('complete', handler)

Playgent.identify({ id: 'u_8f3a2c', name: 'Dana K.', sig: '…' })  // a signed-in reader
Playgent.logout()                                               // same as identify(null)

Playgent.mount(element)  // set up one game element now
Playgent.scan()          // look for new game elements now

To call identify, logout, on or off before the script has loaded, add this line before the script. It queues the calls:

HTML
<script>window.Playgent=window.Playgent||{q:[]};"identify logout on off".split(" ").forEach(function(m){Playgent[m]=Playgent[m]||function(){Playgent.q.push([m,arguments])}})</script>

See signed-in readers for identify.

Page events

Every event is also a DOM event named playgent:<type>. It bubbles up from the game's element, with the data in event.detail, so you can listen without the API:

JavaScript
document.addEventListener('playgent:complete', (event) => {
  const { won, time, hints } = event.detail
  console.log(won ? `Solved in ${time}s` : 'Not solved', `with ${hints} hints`)
})
EventWhenAlso in the data
readyThe game drew its first screen.day, features
viewHalf the game was on screen. Once per page load.day
startA puzzle opened and its clock started.day, level, resumed
hintA hint was used.day, level, count, cost (seconds added)
completeThe puzzle finished, won or lost.day, level, won, time (seconds), hints, revealed, and the game's own numbers, such as guesses
shareThe player pressed Share.day, level
ctaThe player pressed the end-screen button.url, target
rankThe leaderboard placed a finished puzzle.day, level, puzzle, first, ranked, rank, total, verified
errorThe game can't run.code

Every event also has:

  • game: the game type, such as worday.
  • player: the game's id, pg_….
  • element: the game's element on your page.
  • stream: the placement label, when data-stream is set.
  • user: { id, name }, while a reader is signed in.

day is YYYYMMDD. level is null for games without levels.

Error codes

codeThe game showsWhy
originThis game isn’t available on this siteThe site isn't in Your sites.
missingThis game isn’t available right nowNot published, taken offline, deleted, or paused for billing.
unavailableThis game isn’t available right nowThe game was blocked.
gameThis game could not be loadedA network problem, or the game couldn't start.

Google Analytics

With data-datalayer on the element, the game pushes these to window.dataLayer:

Game eventevent in dataLayer
startlevel_start
completelevel_end
shareshare
hintplaygent_hint

Each push has game_name, level_name (the level, or the day), playgent_time and, on level_end, success.

Content-Security-Policy

If your site sends a Content-Security-Policy header, allow the script and the frame:

Text
script-src https://play.playgent.com 'sha256-t4oBvol880Et9gL8QMQu3AfpRFm2vwy3QFzMixuVxlA=';
frame-src https://play.playgent.com;

The hash allows the one-line queue above, exactly as written. Leave it out if you don't use that line. The script writes no HTML into your page, so it also works where Trusted Types are required.

Without the script

You can use a plain iframe:

HTML
<iframe src="https://play.playgent.com/run/v1/?i=pg_7hk2qp0azx"
        title="Today's word search"
        style="width:100%;max-width:560px;height:700px;border:0"
        allow="web-share; clipboard-write"></iframe>

The game then has a fixed height, your page gets no events, and Analytics counts no impressions. Your sites still applies. Use the script when you can.