Embed an OAuth Web Component
Embed code used in sandbox must be changed before being used in production. Some embed parameters, as outlined in the following steps, vary between sandbox and production environments.
Nitro JavaScript Library
The Nitro JavaScript Library is required for all web components. It identifies the web components you want to load and loads them. Do not locally store the library.
For each page where you want to display web components, Nitro JavaScript only needs to be included on the page one time. Once on the page, the script finds your web component embed tags and loads the resources they need to run.
Dynamic Updates
For programs where web components are not regularly refreshed via page navigation, you can use the "update" function to ensure you get the latest data from Nitro. We recommend you leverage this function on components where it's appropriate to get new data in response to a user action. It should not be used to poll our APIs on a timer. Show me example scenarios and code samples
Embed Steps
The following steps describe a generic overview of embedding OAuth web components. Not all web components produce the same embed code. Follow the specific instructions and tips provided with the web component preview and resulting embed code to embed a web component on your site. To embed a block, see Embed a Block.
- Use the Web Component Builder to configure, save, and get the embed code for your web component. Note: Embed code is not available until you save the web component.
- Add the Nitro web component tag on your page in the location where you want the web component to display.
- For Web Components:
- Set the web component tag name: bunchball-profile, bunchball-missions, bunchball-events, bunchball-interaction, bunchball-leaders, bunchball-ots, bunchball-quiz, or bunchball-trophy.
- Where web components support a data-user-id attribute, it should be set, along with using a 3-legged OAuth token.
- For Web Components:
Sandbox Example |
Production Example |
---|---|
Copy
|
Copy
|
- For iframes
- Make sure the "name" attribute in the embed code div name matches the name of the web component you created in Nitro Studio. This uses the web component parameters defined in Nitro Studio.
To bypass pulling the web component data from Nitro Studio, hardcode the name using the data-element-type parameter. Element types include: QUIZ, MINI_PROFILE, EVENTS, MISSIONS, OTS, LEADERS, TROPHY. - The "class" attribute allows nitro.js to recognize the tag as a web component embed tag.
- Where web components support a data-user-id attribute, it should be set, along with using a 3-legged OAuth token.
- Make sure the "name" attribute in the embed code div name matches the name of the web component you created in Nitro Studio. This uses the web component parameters defined in Nitro Studio.
Sandbox and Production Example |
Copy
|
- You can place text or other content between the opening and closing tags to provide loading text or a loading image until the content loads.
You can also provide alternate content to display to your users instead of Nitro content. You may want to do this in case the Nitro servers can't be reached. To provide alternate content, use the <nitro:block>, <nitro:content> and <nitro:alt> tags. - Add Nitro JavaScript to your page as a direct child of the <body> element or after the </body> tag. You should not nest this script under another element, like a <div>. The code that gets executed upon inclusion appends a new <div> to the <body> tag, which cannot happen from within a nested element. This code only needs to be included on the page once. After adding the script, change the values for your environment.
- web component - Add component.min.js BEFORE all web component elements.
Sandbox |
Copy
|
Production |
Copy
|
- iframe - Add nitro.min.js AFTER all web component tags. You must use an "id" attribute of "nitro-js" as well as the src, and data-token attributes. We also recommend you use a data-version attribute which differs in Sandbox and Production environments.
Sandbox |
Copy
|
Production |
Copy
|
Embed Parameters
Parameter |
Description |
Sandbox |
Production |
---|---|---|---|
src (required) |
The URL that the nitro.js script is loaded from (Nitro JavaScript Library). |
"https://components.bunchball.com/nitro/latest/nitro.min.js"
|
|
id (required for iframe only) |
The id attribute of the script element. Must be set to nitro-js. Required for iframe only. |
"nitro-js" |
"nitro-js" |
data-token (required for iframe only) |
The access token received from a token request. For web components, the data token is included in the web component tag.
|
Set to populate the variable for the OAuth token. Replace the parameter with a variable containing the OAuth token at runtime. |
Set to populate the variable for the OAuth token. Replace the parameter with a variable containing the OAuth token at runtime. |
data-server |
|
"https://api.sandbox.bunchball.com" |
Not needed for Production environments |
data-version |
The version of web component code that you want to run. Bunchball recommends that you bind to a version like "v6.1" to avoid instability. |
"latest" |
"v6.1" |
data-cache-enabled |
Allows you turn off caching of session and web component embeds in the browser's localStorage. |
|
|
data-debug |
Enables verbose logging in the browser's development console. |
|
|
data-custom-css |
The URL of your custom stylesheet if you want to override the default styles. |
|
|
Example Embed Code
Web Component
Sandbox |
Production |
---|---|
Copy
|
Copy
|
iframe
Sandbox |
Production |
---|---|
Copy
|
Copy
|
See also