Embedding a Widget
Widgets are embedded by adding scripts and tags directly in the source code of your webpages. These scripts and tags need to be set in accordance with the type of authentication required. Some widgets are embedded to require authentication, while others are embedded to not require authentication.
Caution:
Do not mix authentication modes within the same page or application context. Doing so can cause several issues.- Browser Blocking: Safari and other browsers may block content when authenticated widgets are embedded in non-authenticated pages.
- Authentication Conflicts: Mixing widgets can trigger unexpected authentication workflows.
The best practice is to use the same authentication approach for all widgets on a page. Either all widgets should require OpenID Connect authentication, or all widgets should require pre-authenticated / non-authenticated contexts.
Embedding Content Requiring Authentication
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Page Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="https://ei-util-stage.opower.com/ei/x/embedded-api/core.js?auth-mode=oauth"></script> </head> <body> <div> <opower-widget-neighbor-comparison opower-instance="widget-neighbor-comparison"></opower-widget-neighbor-comparison> </div> <div> <opower-widget-data-browser opower-instance="widget-data-browser"></opower-widget-data-browser> </div> </body> </html>
The instructions below guide you through each step of the process and provide more background information about each the scripts and tags that are required.
Caution:
If you are using Oracle Infinity to track engagement analytics for your website, then you must load your Oracle Analytics Infinity CX Tag on your webpage before completing the steps below. Otherwise, analytics tracking for your widgets will not work. See Tracking User Interaction Analytics for instructions. You can ignore this step if you are not using Oracle Analytics Infinity.To prepare a webpage for embedding content requiring authentication:
Embedding Content Not Requiring Authentication
<!DOCTYPE html> <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Page Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="https://ei-util-stage.opower.com/ei/x/embedded-api/core.js?auth-mode=none"></script> </head> <body> <div> <opower-widget-survey opower-instance="widget-survey-easyopen-splash"></opower-widget-survey> </div> </body> </html>
The instructions below guide you through each step of the process and provide more background information about each of the scripts and tags that are required.
Caution:
If you are using Oracle Infinity to track engagement analytics for your website, then you must load your Oracle Analytics Infinity CX Tag on your webpage before completing the steps below. Otherwise, analytics tracking for your widgets will not work. See Tracking User Interaction Analytics for instructions. You can ignore this step if you are not using Oracle Analytics Infinity.To prepare a webpage for embedding content not requiring authentication:
Tracking User Interaction Analytics
With widgets placed directly into a webpage, utilities can self-serve analytics tracking such as whether or not a user views a widget. This can be accomplished using any analytics platform you prefer.
Oracle Utilities Opower also uses the Oracle Infinity analytics platform to collect user interaction metrics. If you are already using Oracle Infinity to track engagement analytics for your website, then you must load your Oracle Infinity CX Tag in your webpage before adding any Opower-specific widget code snippets. The Oracle Infinity CX Tag is a snippet of JavaScript code that collects data from the webpages that users visit.
Note:
The steps below assume you have already generated an Oracle Infinity CX Tag based on the instructions in CX Tag Quick Start > Standard.To load your Oracle Infinity CX Tag:
- Open the source file of the webpage where you intend to embed an Oracle Utilities Opower widget.
-
Add your Oracle Infinity CX Tag to the section of your webpage that is optimal for your website implementation. For example, in a static webpage design, you could add it to the
<head>tag. For a more dynamic implementation (such as a single-page application), you may add it elsewhere. In the case of a static webpage, the simplest way to ensure the CX Tag is loaded and executed in the proper order is to use thedeferscript tag attribute. See the HTML5 specification for more information about thedeferattribute. An example of how the attribute could look in your CX Tag is as follows:<script src="https://c.oracleinfinity.io/acs/account/{Account GUID}/js/{Tag ID}/odc.js" defer></script>In this example,
{Account GUID}and{Tag ID}are variables which are generated during the process of creating your Oracle Infinity CX Tag. -
Ensure that the script for loading the core widget library comes after the CX Tag. Otherwise, the script for the core widget library will initialize its own Infinity Analytics handler, and will not allow another Infinity Analytics handler to be used. The example below shows that the script for the CX Tag comes first and is followed by the script for the core widget library, which also has its own
deferattribute.<script src="https://c.oracleinfinity.io/acs/account/{Account GUID}/js/{Tag ID}/odc.js" defer></script> <script src="https://util.opower.com/ei/x/embedded-api/core.js" defer></script> -
Follow the rest of the standard steps to embed a widget as described in Embedding a Widget.
Note:
The steps above are meant as an example only. Depending on your implementation, there may be other options to ensure the scripts are loaded and executed in the required order. Contact Your Delivery Team if you need additional guidance.