How Linguineo widgets work
The concepts every widget shares: loading the scripts, authentication, configuration, events and results.
Available widgets#
| Widget | Custom element(s) | Version | Status |
|---|---|---|---|
| Conversation player | <linguineo-conversation> | 1.0.0 | Stable |
| Exercise widgets | <linguineo-multimedia-exercise> and 4 more | 1.1.0 | Stable |
| Conversation transcript | <linguineo-dashboarding-conversation-transcript> | 1.0.0 | Prototype |
Integration in four steps#
- Sign in the learner
The widget needs an access token for the current learner. In production this is a token from your identity provider. See Authentication.
- Load the script
Add the widget script from the Linguineo CDN, or host the files yourself.
- Add the element
Place the custom element where the exercise should appear and configure it with attributes.
- Handle the result
Listen for the
linguineo:endevent to save the score in your own platform.
<!-- 1. load the widget library (module build for modern browsers, ES5 build as fallback) -->
<script type="module" src="https://cdn.linguineo.com/linguineo-conversation/1.0.0/conversation-webcomponents-es2015.js"></script>
<script nomodule src="https://cdn.linguineo.com/linguineo-conversation/1.0.0/conversation-webcomponents-es5.js"></script>
<!-- 2. add the element -->
<linguineo-conversation
id="player"
auth-method="bearer"
access-token="ACCESS_TOKEN_OF_THE_LEARNER"
language="fr"
tutor-language="nl"
scenario-id="503"
answer-type="SPEAKING"
></linguineo-conversation>
<!-- 3. listen for the result -->
<script>
document.getElementById('player').addEventListener('linguineo:end', (event) => {
console.log('Finished with score', event.detail.percentage);
});
</script>Loading the scripts#
Every widget library is published on cdn.linguineo.com in two builds. Load both: modern browsers pick the type="module" build, older browsers the nomodule one.
| Library | Scripts |
|---|---|
| Conversation player | https://cdn.linguineo.com/linguineo-conversation/1.0.0/conversation-webcomponents-es2015.jshttps://cdn.linguineo.com/linguineo-conversation/1.0.0/conversation-webcomponents-es5.js |
| Exercise widgets | https://cdn.linguineo.com/linguineo-exercises/1.1.0/exercises-webcomponents-es2015.jshttps://cdn.linguineo.com/linguineo-exercises/1.1.0/exercises-webcomponents-es5.js |
| Dashboard widgets | https://cdn.linguineo.com/linguineo-dashboarding/1.0.0/linguineo-dashboarding-webcomponents-es2015.jshttps://cdn.linguineo.com/linguineo-dashboarding/1.0.0/linguineo-dashboarding-webcomponents-es5.js |
The version number is part of the URL, so a new release never changes your integration by surprise. Upgrade by changing the version in the URL once you have tested it. Prefer not to load anything from Linguineo URLs? You can host the files yourself; ask us for the package of the version you use.
Authentication#
Widgets call the Linguineo APIs on behalf of the learner. How they authenticate is set with auth-method:
| auth-method | When to use it |
|---|---|
bearer | Recommended. The learner signs in with your identity provider (OpenID Connect / OAuth 2.0) and you pass the access token in access-token. Linguineo validates the token with the public keys of your identity provider. |
default | Linguineo-issued credentials: access-token together with user-id. Only use this when agreed with Linguineo. |
none | No authentication. Only for specific setups agreed with Linguineo. |
For bearer authentication, Linguineo needs the JWKS URL of your identity provider (the URL that publishes its public signing keys). Send it to our technical team: we configure it on our side, you cannot do this step yourself. To try things out before that, the integration guide shows how to use our test identity provider.
Access tokens expire. Refresh the token in your application and set the new value on the element (element.setAttribute('access-token', newToken)) so long sessions keep working.
Attributes and properties#
In HTML you configure a widget with kebab-case attributes, such as tutor-language. From JavaScript or a framework you can also set the matching camelCase property, such as element.tutorLanguage. A few rules apply to all widgets:
- Booleans are passed as the strings
"true"or"false". An attribute you leave out takes its default value. - Objects, such as
connection-configor an exercise definition, are passed as a JSON string. - Languages use two-letter ISO 639-1 codes, such as
fr,nloren.languageis the language the learner practices,tutor-languagethe language of the interface, instructions and translations.
Events and results#
Widgets talk back to your page with DOM events. The events bubble, so you can listen on the element itself or higher up, on document or window.
| Event | Fired when | event.detail |
|---|---|---|
linguineo:end | The learner finishes the exercise or conversation. | The result object (below). |
linguineo:back | The learner presses the back button (only shown with with-back-button="true"). | Nothing. |
const widget = document.querySelector('linguineo-conversation');
widget.addEventListener('linguineo:end', (event) => {
const result = event.detail;
saveScore({ score: result.percentage, points: result.pointsAwarded });
});
widget.addEventListener('linguineo:back', () => {
history.back();
});The result object#
| Field | Type | Description |
|---|---|---|
percentage | number | Score for this attempt, from 0 to 100. |
pointsAwarded | number | Points (stars) earned for this attempt, from 1 to 3. |
needsManualEvaluation | boolean | true when (part of) the answer still needs to be assessed by a teacher. |
durationInMs | number? | Time the learner spent on the exercise, in milliseconds. |
purpose | string | Why the exercise was taken, for example EXERCISE. |
exerciseSessionId | string? | Identifier of this exercise session. |
conversationId | number? | Conversation player only: identifier of the conversation. Use it to show the transcript with the transcript widget. |
taskResultInfos | TaskResultInfo[]? | Conversation player only: the result per task in the scenario. |
Exercise widgets add details that are specific to the exercise type, such as the answers per question. Need the score before the learner finishes, for example when they leave the page? Read element.currentExerciseResult: it returns the result so far.
Connection settings#
By default, widgets connect to the Linguineo production APIs. You only change this when Linguineo gives you other endpoints, for example a proxy or a dedicated environment. Pass the settings as a JSON string in connection-config:
{
"basePath": "https://open-api.linguineo.com/api/v1",
"resourcesBasePath": "https://open-api.linguineo.com/api/v1",
"linguineoBasePath": "https://open-api.linguineo.com/api",
"directCallsToLinguineoBackend": true
}When you pass your own connection-config, include every key, including "directCallsToLinguineoBackend": true. Keys you leave out are not filled in with the defaults.
Frameworks#
Because the widgets are standard custom elements, they work in every framework. Two things to keep in mind:
- Angular: add
CUSTOM_ELEMENTS_SCHEMAto the module or standalone component that uses the element, then bind inputs as properties, for example[accessToken]="token". - React: pass values as attributes (
tutor-language="nl") and attach event listeners through aref, because React does not map custom DOM events toon...props.
Full working examples in plain JavaScript, React and Angular, including token handling and refresh, are in our example repository on GitHub.
