CPQ Web コンポーネントへの CPQ UI の埋め込み

  • リリースバージョン: Australia
  • 更新日 2026年03月12日
  • 所要時間:12分
  • CPQ Web コンポーネントを使用すると、iframe を使用せずに Logik UI を Web ページに埋め込むことができます。コンポーネントの UI はテーマと互換性があるため、ユーザーは UI の外観を簡単に編集できます。

    CPQ Web コンポーネントを使用すると、ユーザーは iframe なしで CPQ UI を Web ページに直接埋め込むことができます。Web コンポーネントの UI はテーマと互換性があるため、ユーザーは UI の外観を簡単に編集できます。

    Web コンポーネントを使用するには、以下が必要です。

    • 展開された詳細計画に関連付けられた構成可能な製品
    • GCP プロパティでホワイトリストに登録されている、宛先 URL を元の Web サイト URL として含む CPQ ランタイムトークン

    ページ上のコンテキスト情報 (ページ URL の SKU など) は、最小限のカスタマイズで Web コンポーネントからアクセスできます。Web コンポーネントには、次の機能もあります。

    • iframe を使用して Logik UI を埋め込む必要がなくなり、iframe に固有のセキュリティ制限や問題を回避できます
    • ページ上の任意の場所でリッスンできるネイティブ HTML イベントをディスパッチします
    • 統合の複雑さを軽減します。たとえば、その Web コンポーネントは、UI の表示と構成のための API 呼び出しを調整します
    • ページ上の HTML に直接アクセスしてサイト上の Logik をより詳細に制御し、親ページとよりシームレスに統合します
    • カスタムテーマと互換性があります

    CPQ Web コンポーネントの埋め込み

    HTML を追加できる任意のページに Web コンポーネントを追加できます。Web コンポーネントを初期化するために必要なフィールドは、URL、ランタイムトークン、および構成可能な製品 ID のみです。

    次のサンプルコードには、Web コンポーネントがどのように機能するかの詳細を示すコメントと、参照用の例が含まれています。

    これには、コンテナや埋め込みコンポーネントに簡単に追加できる最小限のコードが含まれています。製品 ID は手動で入力する必要があります。

    <script
      src="https://TENANT.SECTOR.logik.io/ui/wc-build/logik-wc.es.js"
      type="module"
      ></script>
      <logik-ui 
      runtime-token="RUNTIME_TOKEN"
      tenant-api-url="TENANT.SECTOR.logik.io"
      product-id="PRODUCT_ID"
      >
      </logik-ui>

    次のサンプルコードは、全ページの例を表しています。これにより、ユーザーは簡単に複数のパラメーターを渡し、ページから製品 ID を読み取ることができます。

    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <title>Web Component Sandbox</title>
        <script
          type="module"
          src="https://renderdraw02.demo01.logik.io/ui/wc-build/logik-wc.es.js"
        ></script>
      </head>
      <body>
        <logik-ui></logik-ui>
    
        <script>
          // Type Definitions
          /**
           * @typedef {Object} BomProduct
           * @property {string} id - Product identifier
           * @property {number} price - Unit price of the product
           * @property {number} quantity - Quantity of the product
           * @property {('SALES'|'MANUFACTURING')} bomType - Type of BOM
           * @property {string} type - Product type (e.g., 'accessory')
           * @property {number} rollUpPrice - Rolled up price including child products
           * @property {number} extPrice - Extended price (price * quantity)
           * @property {number} level - Hierarchy level in the BOM structure
           * @property {{ selected: boolean, disabled: boolean }} selection - Selection state
           * @property {number} extList - Extended list price
           * @property {number} list - List price
           * @property {string} displayName - Display name of the product
           * @property {string|null} parentProduct - ID of parent product if nested
           */
    
          /**
           * @typedef {Object} BomData
           * @property {{
           *   products: Array<BomProduct>,
           *   total: number,
           *   totalPages: number,
           *   totalItems: number,
           *   errorMessage: string|null,
           *   incompletePricing: boolean
           * }} newProducts - Updated products in the BOM
           */
    
          /**
           * @typedef {Object} LogikConfigurationData
           * @property {string} configurationId - The unique identifier for the configuration
           * @property {string} productId - The product identifier
           * @property {Object} fields - The current state of all fields in the configuration
           * @property {BomData} [bomData] - Bill of Materials data (only present in BOM events)
           * @property {Object} [quoteData] - Quote data (only present in Quote events)
           */
    
          /**
           * @typedef {Object} QuoteData
           * @property {Object} quote - Quote-specific data
           * @property {string} quote.SBQQ__PricebookId__c - Pricebook identifier
           * @property {string} quote.LGK__QueriedEditAccess__c - Edit access status
           * @property {Object} product - Configured product data
           * @property {string} product.configuredProductId - ID of the configured product
           * @property {Object} product.configurationAttributes - Configuration attributes
           * @property {string} product.configurationAttributes.LGK__Logik_Id__c - Logik configuration ID
           * @property {Object} product.configurationAttributes.LGK__Configuration_Data__c - Configuration data
           * @property {Array} product.configurationAttributes.LGK__Configuration_Data__c.items - Configuration items
           * @property {Object} product.optionConfiguration - Option configuration data
           * @property {Array} product.optionConfiguration.Dynamic - Dynamic option configurations
           */
    
          // Configuration
          const logikUrl = 'https://renderdraw02.demo01.logik.io';
          const runtimeToken = 'YIFFI0dluM7ULhibRGR2GB_3F2npxSn_Zw';
          const productId = '01t8c00000RzlKoAAJ';
    
          const fields = [
            { variableName: 'exampleBooleanField', value: true },
            {
              variableName: 'exampleArrayField',
              value: ['alpha', 'delta', 'beta'],
            },
            { variableName: 'exampleStringField', value: 'left' },
            { variableName: 'exampleNumberField', value: 21 },
          ];
    
          /**
           * Initializes the Logik UI web component with the specified configuration parameters.
           * @param {string} productId - The unique identifier for the product. This is a configurable product id in the logik Admin
           * @param {string} runtimeToken - The authentication token for runtime access. This can be created in the logik Admin under Runtime Clients. The token must have include an origin matching the url of the page that is hosting the web component.
           * @param {string} tenantApiUrl - This should be set to the url of your logik tenant. eg https://example.demo01.logik.io
           * @param {string} [assetURL] - Optional URL for asset resources. If provided, sets the asset-url attribute. Defaults to the provided tenantApiUrl. You will most likely not need to set this.
           * @param {Array<{
           *   variableName: string,
           *   value: string | number | boolean | Array<string>
           * }>} [fields] - A list of field values to set in the initial state of the configuration.
           * @returns {void}
           */
          function initLogikUI(productId, runtimeToken, tenantApiUrl, assetURL, fields) {
            const logikuiEl = document.querySelector('logik-ui');
            logikuiEl.setAttribute('product-id', productId);
            logikuiEl.setAttribute('runtime-token', runtimeToken);
            logikuiEl.setAttribute('tenant-api-url', tenantApiUrl);
            if (assetURL) {
              logikuiEl.setAttribute('asset-url', assetURL);
            }
            if (fields) {
              logikuiEl.setAttribute('fields', JSON.stringify(fields));
            }
          }
    
          // Initialize the component
          initLogikUI(productId, runtimeToken, logikUrl, false, fields);
    
          // Event Listeners
          /**
           * Event fired when the user cancels the configuration. After this event is received,
           * the configuration will be terminated and the logik-ui component should be unmounted.
           * @event logik-ui:cancel
           * @type {CustomEvent}
           * @property {Object} detail - An empty object indicating the configuration was cancelled
           */
          window.addEventListener('logik-ui:cancel', function (event) {
            console.log('Cancel event received', event);
          });
    
          /**
           * Event fired when the user generates a quote. After this event is received,
           * the configuration will be terminated and the logik-ui component should be unmounted.
           * @event logik-ui:quote
           * @type {CustomEvent}
           * @property {Object} detail - The event details
           * @property {QuoteData} detail.data - The quote data
           */
          window.addEventListener('logik-ui:quote', function (event) {
            console.log('Quote event received', event);
          });
    
          /**
           * Event fired when the BOM changes during configuration
           * @event logik-ui:bom
           * @type {CustomEvent}
           * @property {Object} detail - The event details
           * @property {LogikConfigurationData} detail.data - The configuration data with BOM information
           */
          window.addEventListener('logik-ui:bom', function (event) {
            console.log('BOM event received', event);
          });
        </script>
      </body>
    </html>