Installation

Include the Canopy Connect initialization script on your site. It should always be loaded
directly from https://cdn.usecanopy.com, rather than hosted yourself.

<script src="https://cdn.usecanopy.com/v2.1.0/canopy-connect.js"></script>

Usage

const handler = CanopyConnect.create({
  // [Optional string] to skip the first screen in the widget, you can supply a consent token. See the “Usage with Consent API” section for more details.
  consentToken: "<CONSENT_TOKEN_OBTAINED_FROM_OUR_CONSENT_API>",
  publicAlias: "<YOUR_WIDGET_PUBLIC_ALIAS>",
  onAuthenticationSuccess: (data) => {
    // [Optional callback] called when user is authenticated
  },
  onExit: (err, data) => {
    // [Optional callback] called when user exits flow (including after authenticating successfully)
  },
  onDestroy: () => {
    // [Optional callback] called when you use the `handler.destroy()` method below
  },
  onSelectCustomInsuranceProvider: ({ providerName }) => {
    // [Optional callback] called when user selects a custom insurer on a link that has the custom insurer button enabled
  },
  pullMetaData: {
    // arbitrary JSON-serializable data to set as Pull.meta_data
  },
});
handler.open(); // show Canopy Connect modal
handler.close(); // close Canopy Connect modal
handler.destroy(); // destroy Canopy Connect modal (optional - removes all DOM elements and event listeners)