@go1/go1-embedding-react-sdk

中文文档
0.13.1发布于 2026/06/25ISCTypeScriptCommonJS零依赖近 30 天下载 5.9万

A React library to embed Go1 content into your website.

原始使用文档
文档目录11 节
  1. Installation
  2. Usage
  3. Types
  4. Function: useGo1ContentView
  5. Usage
  6. Function: sendMessageToGo1
  7. Usage
  8. Function: onGo1MessageReceived
  9. Usage
  10. Go1 Message Example Payloads
  11. Support

Go1 Embedding React SDK

A React hook to embed a Go1 content view in your site. Includes two-way messaging between your site and the Go1 content view.

Installation

npm install @go1/go1-embedding-react-sdk

Usage

Import the hook from the library and use it in your functional components.

import { useMemo, useCallback } from 'react';
import { ContentViewProps, useGo1ContentView } from '@go1/go1-embedding-react-sdk';

export function YourHostingComponent() {
  const onGo1MessageReceived = useCallback((message) => {
    console.log('Received postMessage from Go1');
    console.log(message);
  }, []);

  const options = useMemo<ContentViewProps>(() => {
    return {
      feature: 'ai-chat',
      portalURL: 'learning-incorporated-usa.mygo1.com',
      onGo1MessageReceived,
    };
  }, []);

  const { sendMessageToGo1, ContentView } = useGo1ContentView(options);

  return (
    <div style={{ width: '100vw', height: '100vh' }}>
      <ContentView />
    </div>
  );
}

APIs

Types

export type OnGo1MessageReceived = (message: Go1Message) => void;

export type SendMessageToGo1 = (message: Go1Message) => void;

export type IframesMap = { [key: string]: HTMLIFrameElement };

export interface FeatureAttributeCommon {
  shouldSuppressPreview?: boolean;
  shouldSuppressOpeningPlayer?: boolean;
  shouldShowSelectWelcomeModal?: boolean;
  shouldSuppressBookmark?: boolean;
  shouldSuppressBookmarkAction?: boolean;
  shouldSuppressPlaylistAdministration?: boolean;
  shouldSuppressShareLink?: boolean;
  shouldSuppressLibrary?: boolean;
  shouldSuppressPlaylist?: boolean;
  shouldSuppressCopyRightFooter?: boolean;
  shouldSuppressPlay?: boolean;
  shouldSuppressExport?: boolean;
  shouldSuppressAIAgents?: boolean;
  shouldSuppressAIDiscoveryAgent?: boolean;
  shouldSuppressAIReportingAgent?: boolean;
  contentScope?: 'subscription' | 'library';
  shouldSuppressEndorsement?: boolean;
}


export type ThemeMode = 'light' | 'dark';

export interface ThemeModeInformation {
  mode: ThemeMode;
}

export interface ThemeInformation {
  /** Hex string, starting with a #. Example #0437F2 */
  accent: string;
  mode?: ThemeMode;
}

export type Go1MessageType =
  | 'preview_start_content'
  | 'preview_close'
  | 'preview_add_content_success'
  | 'preview_add_content_failure'
  | 'preview_remove_content_success'
  | 'preview_remove_content_failure'
  | 'parent_show_preview'
  | 'set_additional_embedding_data'
  | 'go1_app_initialised'
  | 'ott_required'
  | 'search_result_selected'
  | 'search_filter_toggle'
  | 'pass_ott'
  | 'logout',
  | 'sync_content'
  | 'inter_feature_navigation'
  | 'side_drawer_open'
  | 'side_drawer_close'
  | 'swap_out_open'
  | 'swap_out_close'
  | 'play_content'
  | 'library_content_added'
  | 'library_content_removed'
  | 'library_content_exported'
  | 'save_content';

export interface Go1Message {
  type: Go1MessageType;
  payload?: any;
}


export interface FeatureAttributeCommon {
  shouldSuppressPreview?: boolean;
  shouldSuppressOpeningPlayer?: boolean;
  shouldShowSelectWelcomeModal?: boolean;
  shouldSuppressBookmark?: boolean;
  shouldSuppressBookmarkAction?: boolean;
  shouldSuppressPlaylistAdministration?: boolean;
  shouldSuppressShareLink?: boolean;
  shouldSuppressLibrary?: boolean;
  shouldSuppressPlaylist?: boolean;
  shouldSuppressCopyRightFooter?: boolean;
  shouldSuppressPlay?: boolean;
  shouldSuppressExport?: boolean;
  shouldSuppressAIAgents?: boolean;
  shouldSuppressAIDiscoveryAgent?: boolean;
  shouldSuppressAIReportingAgent?: boolean;
  contentScope?: 'subscription' | 'library';
  shouldSuppressEndorsement?: boolean;
}

/**
 * @deprecated Use `feature: 'discovery-agent'` instead.
 * Used to configure the `ai-chat` feature.
 */
export interface FeatureAttributesAIChat extends FeatureAttributeCommon {
  intent?: 'skill_gap' | 'improve_skills' | 'next_role' | 'aspirations';
  message?: string; // The desired message to start the chat, which will be shown to the user
  existingSkills?: string[]; // max items 7, any more are discarded
  desiredSkills?: string[]; // max items 7, any more are discarded
  desiredRole?: string; // e.g. "Senior Account Manager"
  showFooter?: boolean // Whether to show/hide the footer, defaults to true
}

/**
 * Used to configure the `discovery-agent` feature
 */
export interface FeatureAttributesDiscoveryAgent extends FeatureAttributeCommon {
  message?: string; // The desired message to start the chat, which will be shown to the user
}

/**
 * Used to configure the `preview` feature
 */
export interface FeatureAttributesPreview extends FeatureAttributeCommon {
  id: number;
  startWith1Player?: boolean;
  showFooter?: boolean;
  contentRatingType?: 'no rating' | 'five star rating' | 'like rating';
}

/**
 * Used to configure the `wallet` feature
 */
export interface FeatureAttributesWallet extends FeatureAttributeCommon {
  walletMode: 'setup' | 'main';
  deepLink?: string;
  oneClickBuyUrl?: string;
}

export interface FeatureAttributesLibrary extends FeatureAttributeCommon, FeatureAttributesRetirement {
  libraryEmptyStateDescription?: string;
  shouldShowLibraryTabs?: boolean;
}

export interface FeatureAttributesRetirement extends FeatureAttributeCommon {
  shouldShowAlternativesSearchButton?: boolean;
  shouldShowNotificationEmailRegisterSwitch?: boolean;
}

export interface FeatureAttributesSearch extends FeatureAttributeCommon {
  searchTerm?: string;  // If the embedding search feature includes a search term, the app will initialize with the pre-filled search term.
}
export interface FeatureAttributesProspect {
  isProspectExperience?: boolean;
}

export interface FeatureAttributesGo1LearnSearch
  extends FeatureAttributeCommon,
    FeatureAttributesProspect {
  searchTerm?: string; // If the embedding search feature includes a search term, the app will initialize with the pre-filled search term.
  searchProvider?: string; // If the embedding search feature includes a search provider, the app will initialize with the pre-filled search provider.
}

export type FeatureAttributesRecommendations = Omit<FeatureAttributesGo1LearnSearch, 'searchProvider'> & {
  providers?: string[]; // If the embedding recommendations feature includes a search providers, the app will initialize with the pre-filled search provider
  skills?: string[]; // If the embedding recommendations feature includes a search skills, the app will initialize with the pre-filled search skills
  topics?: string[]; // If the embedding recommendations feature includes a search topics, the app will initialize with the pre-filled search topics
  sort?: string; // If the embedding recommendations feature includes a search sort, the app will initialize with the pre-filled search sort
}

export type FeatureAttributes =
  | FeatureAttributesAIChat
  | FeatureAttributesDiscoveryAgent
  | FeatureAttributesPreview
  | FeatureAttributesWallet
  | FeatureAttributesLibrary
  | FeatureAttributesSearch
  | FeatureAttributesRecommendations;

export interface AdditionalUserInfo {
  jobTitle: string;
}

export type FeatureType =
  /** @deprecated Use 'discovery-agent' instead. */
  | 'ai-chat'
  | 'discovery-agent'
  /** @deprecated Use 'admin-curation' instead. */
  | 'content-hub'
  | 'preview'
  | 'search'
  | 'admin-curation';

export interface InitOptions {
  /** Mandatory identifier for the embedded feature */
  feature: FeatureType;
  /** Optional element id to search for, and use as the parent for the Go1 content view (use either this or `iframeParentElement`, not both) */
  iframeParentId?: string;
  /** Optional element to use as the parent for the Go1 content view (use either this or `iframeParentId`, not both) */
  iframeParentElement?: HTMLElement;
  /** Optional parameters to configure the feature. See associated types for examples */
  featureAttributes?: FeatureAttributes;
  /** Optional Go1 portal URL, used for login purposes if no `oneTimeToken` is provided */
  portalURL?: string;
  /** Optional function that is invoked when the Go1 content view emits a message */
  onGo1MessageReceived?: OnGo1MessageReceived;
  /** Optional end user information that can enhance the context and provide a better experience. No PII is needed, please do not send any. */
  additionalUserInfo?: AdditionalUserInfo;
  /** Optional UI configuration */
  themeInformation?: ThemeInformation | ThemeModeInformation;
  /** Optional one time token that is used to pre-authorize the user without them needing to log in */
  oneTimeToken?: string;
  /** Optional OAuth token that is used to pre-authorize the user without them needing to log in */
  accessToken?: string;
  /** Optional Id that let us know which integration system users are coming from (will be required in the future)*/
  integrationSystemId?: string;
  /** Optional Id that let us know which integration system users are coming from, if using an intermediary system to embed */
  presentingIntegrationSystemId?: string;
   /** Optional flag to control JWT persistence in browser storage, if false, JWT will not be stored in localStorage, sessionStorage, or cookies */
  persistJWT?: boolean;
}

content-hub is deprecated and will be removed in a future major release. Use admin-curation for new integrations. Existing content-hub requests are redirected server-side to admin-curation during the deprecation window.

ai-chat is deprecated and will be removed in a future major release. Use discovery-agent for new integrations.

Function: useGo1ContentView

A react hook that will return

  • sendMessageToGo1: A function that allows you to send a message to the Go1 content view
  • ContentView: A react component to render the Go1 content view
function useGo1ContentView(options: InitOptions): {
  sendMessageToGo1: SendMessageToGo1;
  ContentView: () => React.JSX.Element;
};

Usage

const onGo1MessageReceived = useCallback((message) => {
  console.log('Received postMessage from Go1');
  console.log(message);
}, []);

const options = useMemo<ContentViewProps>(() => {
  return {
    feature: 'ai-chat',
    portalURL: 'learning-incorporated-usa.mygo1.com',
    featureAttributes: {
      shouldSuppressShareLink: true,
    },
    persistJWT: false,
    onGo1MessageReceived,
    additionalUserInfo: {
      jobTitle: 'Sales development representative',
    },
    themeInformation: {
      accent: '#0437F2',
      mode: 'dark',
    },
    oneTimeToken: '907687a6e81a458190fe4c21f05ee689',
    integrationSystemId: 'int_nI7rPykBRm0C',
  };
}, []);

const { sendMessageToGo1, ContentView } = useGo1ContentView(options);

// now to render the <ContentView>

Function: sendMessageToGo1

Send a message to the Go1 content view. Useful to control the user experience when an event starts on your website and the Go1 content view needs to be aware of it (and potentially perform other actions - this is feature dependent.)

An example of its usage is below.

function sendMessageToGo1(message: Go1Message): void;

Usage

const message = {
  type: 'logout',
  payload: {},
};
sendMessageToGo1(message);

Function: onGo1MessageReceived

Respond to events that have occurred in the Go1 content view. Useful to control the user experience when an event starts in the Go1 content view and your website needs to be aware of it.

Usage

const onGo1MessageReceived = (message) => {
  switch (message.type) {
    case 'enrolment_created': {
      const { userId, courseId } = message.payload;
      // perform appropriate actions for when a new enrolment is created
      break;
    }
    case 'category_favourite_added': {
      const { userId, category } = message.payload;
      // perform appropriate actions for when a new category is favourited
      break;
    }
    default:
      break;
  }
};

Go1 Message Example Payloads

Item has been added to the library

{
  "type": "library_content_added",
  "payload": {
    "id": "3510462",
    "action_type": "admin-add",
    "timestamp": "2026-06-16T02:13:45.123Z",
    "type": "lo",
    "lo_type": "course"
  }
}

Item has been removed from the library

{
  "type": "library_content_removed",
  "payload": {
    "id": "3510462",
    "action_type": "admin-remove",
    "timestamp": "2026-06-16T02:13:45.123Z",
    "type": "lo",
    "lo_type": "course"
  }
}

Selected library items have been exported through postMessage

{
  "type": "library_content_exported",
  "payload": {
    "items": [
      { "id": "3510462", "type": "lo" },
      { "id": "3510463", "type": "lo" }
    ]
  }
}

Item bookmark action has been requested by a learner while shouldSuppressBookmarkAction is enabled

{
  "type": "save_content",
  "payload": {
    "id": "3510462",
    "action_type": "learner-save",
    "timestamp": "2026-06-16T02:13:45.123Z",
    "type": "lo",
    "lo_type": "course"
  }
}

Item bookmark action has been requested by an admin while shouldSuppressBookmarkAction is enabled

{
  "type": "save_content",
  "payload": {
    "id": "3510462",
    "action_type": "admin-save",
    "timestamp": "2026-06-16T02:13:45.123Z",
    "type": "lo",
    "lo_type": "course"
  }
}

Support

https://www.go1.com/developers

版本与发布记录

@go1/go1-embedding-react-sdk 共发布 87 个版本,首次发布于 2023/07/11;过去 12 个月发布了 9 个版本。

版本发布日期距今
0.13.1latest2026/06/254 个月前
0.13.02026/06/244 个月前
0.12.02026/06/234 个月前
0.11.02026/06/224 个月前
0.9.42026/05/146 个月前
0.9.32026/05/136 个月前

关于 @go1/go1-embedding-react-sdk 的常见问题

@go1/go1-embedding-react-sdk 是什么?

A React library to embed Go1 content into your website.

如何安装 @go1/go1-embedding-react-sdk?

在项目目录运行 npm install @go1/go1-embedding-react-sdk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=16.8)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@go1/go1-embedding-react-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@go1/go1-embedding-react-sdk 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@go1/go1-embedding-react-sdk 可以商用吗?

@go1/go1-embedding-react-sdk 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@go1/go1-embedding-react-sdk 的下载量有多少?

根据 npm 官方下载统计,@go1/go1-embedding-react-sdk 在 2026/10/17 – 2026/11/15 这 30 天内被下载 59,142 次,日均约 1,971 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@go1/go1-embedding-react-sdk 还在维护吗?

最新版本 0.13.1 发布于 2026/06/25(4 个月前);至今共发布 87 个版本,其中过去 12 个月发布了 9 个;首次发布于 2023/07/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。