Exercise widgets

Five web components for interactive, vocabulary, word game, pronunciation and verb exercises.

StableVersion 1.1.0

Besides conversations, Linguineo offers interactive exercises, vocabulary and verb trainers, word games and pronunciation exercises. They all come from one library, with one custom element per exercise family. All elements share the same attributes, events and result format.

Elements#

ElementExercise family
linguineo-multimedia-exerciseInteractive exercises around text, images, audio and video, such as multiple choice, gap fill, drag and drop, matching and open speaking or writing tasks.
linguineo-vocabulary-exerciseVocabulary trainer: learn and practice new words in short sessions.
linguineo-wordgame-exerciseWord games to practice vocabulary in a playful way.
linguineo-pronunciation-exercisePronunciation exercises: listen to a model, record yourself and get feedback down to the individual sound.
linguineo-verbs-exerciseVerb trainer: practice conjugations.

Use the element that matches the type of the exercise you load. If you build a generic exercise page, choose the element based on the exercise type in the exercise definition.

Load the library#

HTML
<script type="module" src="https://cdn.linguineo.com/linguineo-exercises/1.1.0/exercises-webcomponents-es2015.js"></script>
<script nomodule src="https://cdn.linguineo.com/linguineo-exercises/1.1.0/exercises-webcomponents-es5.js"></script>

One library registers all five elements.

The exercise definition#

Unlike the conversation player, which loads a scenario by its ID, an exercise widget receives the complete exercise definition as a JSON string in the exercise attribute. You usually get this JSON from the Linguineo content creation API. Fetch it in your back end and pass it on unchanged.

Pass the definition exactly as you received it, as a string. The widget parses it itself (JSON.parse), so passing an object or a modified copy will not work.

Quick start#

HTML
<linguineo-vocabulary-exercise
  id="exercise"
  language="fr"
  tutor-language="nl"
  auth-method="bearer"
></linguineo-vocabulary-exercise>

<script type="module" src="https://cdn.linguineo.com/linguineo-exercises/1.1.0/exercises-webcomponents-es2015.js"></script>
<script nomodule src="https://cdn.linguineo.com/linguineo-exercises/1.1.0/exercises-webcomponents-es5.js"></script>

<script>
  const el = document.getElementById('exercise');

  // the exercise definition (JSON string), loaded through your own back end
  fetch('/my-backend/exercises/123')
    .then((res) => res.text())
    .then((exerciseJson) => {
      el.setAttribute('access-token', getAccessToken()); // token of the signed-in learner
      el.setAttribute('exercise', exerciseJson);
    });

  el.addEventListener('linguineo:end', (event) => {
    console.log('Exercise finished', event.detail);
  });
</script>

Attributes#

All five elements accept these attributes. The camelCase name below each attribute is the property to use from JavaScript or a framework.

AttributeTypeDefaultDescription
exercisereqexerciseJSON stringThe complete exercise definition. See The exercise definition.
access-tokenreqaccessTokenstringAccess token of the learner. See Authentication.
auth-methodauthMethodenumdefaultbearer, default or none. Use bearer with a token from your own identity provider.
user-iduserIdstringLinguineo user ID. Only needed with default authentication.
usernameusernamestringUser name that goes with user-id. Only needed with default authentication.
languagelanguagestringnlISO 639-1 code of the language the learner practices.
tutor-languagetutorLanguagestringnlISO 639-1 code of the language for instructions and translations.
applicationapplicationstringApp identifier. Only set this if Linguineo gave you one.
language-levellanguageLevelstringCEFR level of the learner: A1, A2, B1, B2, C1 or C2.
with-back-buttonwithBackButtonbooleanfalseShow a back button. Pressing it fires linguineo:back.
header-with-simple-backgroundheaderWithSimpleBackgroundbooleantrueUse a plain background for the exercise header.
auditive-playback-activeauditivePlaybackActivebooleantruePlay audio (such as the pronunciation of words) automatically.
auditive-playback-with-iconauditivePlaybackWithIconbooleanfalseShow a speaker icon to play audio.
automatic-content-translations-enabledautomaticContentTranslationsEnabledbooleantrueShow automatic translations of the content in the tutor language.
sound-effects-enabledsoundEffectsEnabledbooleantrueEnable interface sound effects.
stop-recording-on-silencestopRecordingOnSilencebooleantruePronunciation and verb exercises only: stop recording automatically when the learner stops speaking.
exercise-styling-classexerciseStylingClassstringCSS class for the main color scheme of the exercise.
alternate-styling-classalternateStylingClassstringCSS class for the alternate color scheme.
connection-configconnectionConfigJSON stringLinguineo APIsCustom API endpoints. See Connection settings.

Events and results#

The exercise widgets fire the same events as the conversation player:

EventFired whenevent.detail
linguineo:endThe learner finishes the exercise.The result object.
linguineo:backThe learner presses the back button.Nothing.

The result contains the shared fields (percentage, pointsAwarded, needsManualEvaluation, durationInMs, purpose, exerciseSessionId) plus details for the exercise family, such as the answers per question, word or sentence. See Events and results for the shared fields. To read the result before the learner finishes, use element.currentExerciseResult.

Angular#

Add CUSTOM_ELEMENTS_SCHEMA to your module or standalone component and bind the inputs as properties:

Angular template
<linguineo-vocabulary-exercise
  [exercise]="exerciseAsJson"
  [language]="exercise.language"
  [tutorLanguage]="tutorLanguage"
  [withBackButton]="false"
  [soundEffectsEnabled]="true"
  [accessToken]="user?.accessToken"
  [authMethod]="'bearer'"
></linguineo-vocabulary-exercise>

The event name contains a colon, so listen for it with a host listener instead of an (event) binding in the template:

Angular component
@HostListener('window:linguineo:end', ['$event'])
onExerciseFinished(event: CustomEvent) {
  this.saveResult(event.detail);
}

React#

Pass values as attributes and attach event listeners through a ref:

React (JSX)
import { useEffect, useRef } from 'react';

export function VocabularyExercise({ exerciseJson, accessToken, onEnd }) {
  const ref = useRef(null);

  useEffect(() => {
    const el = ref.current;
    const handleEnd = (event) => onEnd(event.detail);
    el.addEventListener('linguineo:end', handleEnd);
    return () => el.removeEventListener('linguineo:end', handleEnd);
  }, [onEnd]);

  return (
    <linguineo-vocabulary-exercise
      ref={ref}
      exercise={exerciseJson}
      language="fr"
      tutor-language="nl"
      auth-method="bearer"
      access-token={accessToken}
    />
  );
}
Stuck somewhere?Our technical team is happy to help with your integration.
Contact us