Login & personalization · Demo 1 of 4

Pass the logged-in reader to Riddle

Your site already knows who is logged in. Three lines of JavaScript hand that to the Riddle, so the quiz can greet readers by name and treat members differently.

Riddle feature: data layer variables

Setup: about 10 minutes

Works with any login system

Live Riddle

Quiz · 3 questions

[[dg-riddle VOZcrfDm h=600]]

Live Riddle from project 6200. Use “Guest view” in the inspector to see what logged-out readers get.

[[dg-inspector]]

What just happened

From your login to the quiz text in three steps.

01

WordPress knows you

The page is rendered for a logged-in reader, so the server has the display name.

02

The page fills riddleDataLayer

Before the Riddle loads, the page pushes is_logged_in and display_name into window.riddleDataLayer.

03

Riddle swaps in the variable

The question text holds a Display Name variable. Riddle replaces it, or shows the fallback “reader”.

Build it yourself

The code and the Riddle settings.

1 · On your page

Add this before the Riddle embed script. The example uses WordPress; any server or login SDK works the same way.

<!-- before the Riddle embed -->
<script>
  window.riddleDataLayer = window.riddleDataLayer || [];
  window.riddleDataLayer.push(
    { key: 'is_logged_in', value: '<?php echo is_user_logged_in() ? 1 : 0; ?>' },
    { key: 'display_name', value: '<?php echo esc_js( wp_get_current_user()->display_name ); ?>' }
  );
</script>
<script src="https://www.riddle.com/embed/build-embedjs/embedV2.js"></script>

2 · In the Riddle Creator

Four settings, no custom code inside the Riddle.

  1. Publish → Data layer: add the keys is_logged_in and display_name.
  2. Question text: insert the Display Name variable, with the fallback “reader”.
  3. Optional logic: branch on is_logged_in equals 1 to treat members differently.
  4. Embed: use the script embed code, not a plain iframe, so the data layer reaches the Riddle.

Privacy & security

Pass only what the Riddle needs.

  • A first or display name is enough for a greeting. Leave email addresses out of the data layer.
  • Escape values on the server (esc_js in WordPress) so a user name cannot break the page.
  • If you save data layer values with responses, cover them in your privacy notice like any other personal data.

Next demo · 2 of 4

Logged-in readers only: a login form inside the Riddle

Open demo →
Scroll to Top