@gobistories/gobi-web-integration

中文文档
6.19.13发布于 2026/10/16Apache-2.0TypeScriptCommonJS近 30 天下载 2万

This library will let you put your Gobi stories on your site.

原始使用文档
文档目录12 节
  1. Story Bubbles Demo
  2. Troubleshooting & FAQ
  3. Technical Documentation
  4. Story Bubbles
  5. Creating a standalone player
  6. Browser Support
  7. Embed Options
  8. Events
  9. Embedded player
  10. Player Options
  11. Methods
  12. Opening Gobi Stories Programmatically

Gobi Web Integration

Welcome to Gobi Web Integration. This library will let you put your Gobi stories on your site. If you don't have any Gobi Stories yet sign up in our Studio to get access to our production tools.

Story Bubbles Demo

To easily test the most used options, go to the code snippet editor in our Studio.

Troubleshooting & FAQ

Bubbles don't show

See the console. Can you spot any errors? Try to understand them. If there seems to be a bug in the library, please email us.

Vidoes or thumbnails don't play and I see Content Security Policy errors

You may see an error similar to:

Refused to load media from 'https://res.cloudinary.com/gobi-technologies-as/...' because it violates the following
Content Security Policy directive: ...

If so, you need to update your Content-Security-Policy HTTP headers to include blob: and the sources that we use.

Sources used by our library are:

Example using the fallback default-src:

default-src 'self' blob: <your other sources> https://widget.gobistories.com https://api.gobistories.com https://res.cloudinary.com/gobi-technologies-as/;

Example using stricter fetch directives:

script-src 'self': <your other sources> https://widget.gobistories.com/;
connect-src 'self': <your other sources> https://api.gobistories.com/;
media-src 'self' blob: <your other sources> https://res.cloudinary.com/gobi-technologies-as/;
img-src 'self' blob: <your other sources> https://res.cloudinary.com/gobi-technologies-as/;

My page scrolls when opening a story

If your page scrolls to the top when opening a story, this is usually caused by the height styling for the HTML tag of your page. Removing or replaceing this with min-height usally solves the problem.

Technical Documentation

Story Bubbles

Adding bubbles to your pages and content requires three steps:

  1. Load our script
  2. Add a placeholder element where you want the bubbles
  3. Call our code to create the bubbles

You can generate the required code within our Studio, or refer to the documentation below.

Adding bubbles with Gobi.discover()

This is the recommended way to add story bubbles to your page. Add your placeholder where you want the bubble to appear, add the gobi-stories class and specify options using data attributes:

<div
  class="gobi-stories"
  data-gobi-stories="story-id another-story-id"
  data-gobi-kebab-cased-option="value"
  data-gobi-some-other-kebab-cased-option="value"
></div>

If you would like to configure titles or thumbnail urls per story, then you can add them as child elements:

<div class="gobi-stories" data-gobi-kebab-cased-option="value" data-gobi-some-other-kebab-cased-option="value">
  <div data-gobi-story="story-id" data-gobi-title="About Us"></div>
  <div data-gobi-story="another-story-id" data-gobi-title="Our Product" data-gobi-thumbnail-url="..."></div>
</div>

Note that you can add new lines to title by using a new line in the HTML, or by adding \n with the title itself.

See the Bubble Options section for available options. Note that options should be converted to kebab case and prefixed with data-gobi-.

You can then load our script and run gobi.discover():

<head>
  <script src="https://widget.gobistories.com/gwi/6" async onload="gobi.discover()"></script>
</head>

You can pass global options to discover() that will be used for all bubbles on the page as defaults. See Bubble Options for more information:

gobi.discover({
  bubbleSize: '120px',
  color: 'blue',
});

The global options will be used when they are not overridden by individual embed options.

Adding bubbles with an inline script

Another way to add Gobi stories to your page is by using inline javascript.

<head>
  <script src="https://widget.gobistories.com/gwi/6"></script>
</head>
<body>
  <div id="container"></div>
  <script>
    new gobi.Bubbles({
      container: '#container',
      stories: [
        {
          id: 'story-key',
          title: 'Some Title',
        },
        {
          id: 'another-story-key',
          title: 'Some Another Title',
        },
      ],
    });
  </script>
</body>

Creating a standalone player

You can also show story player directly in the page without using bubbles.

<head>
  <script src="https://widget.gobistories.com/gwi/6"></script>
</head>
<body>
  <div id="container"></div>
  <script>
    new gobi.Player({
      container: '#player-container',
      storyId: 'story-key',
      on: {
        videoPlay: function() {
          console.log('played the video!');
        },
      },
    });
  </script>
</body>

See Player Options for details.

Installing as a Package

npm version

Developers may prefer to install Gobi Web Integration as a package dependency:

npm install --save @gobistories/gobi-web-integration
import { Bubbles } from '@gobistories/gobi-web-integration';

// Create bubbles
new Bubbles({
  container: '#container',
  bubbleSize: '200px',
});

// Create a Player
new Player({
  container: '#container',
  storyName: 'story-id',
  playerOptions: {
    on: {
      videoPlay: function() {
        console.log('played the video!');
      },
    },
  },
});

Browser Support

The library will work well in Chrome, Firefox, Safari, and Opera. The library lets users in IE view the story, but UX and functionality might be a bit limited compared to modern browsers.

Embed Options

optiondefaultdescription
container#gobi-hereRequired for inline javascript. String. Query Selector for HTMLElement. Container where the module will be embed.
color#15d6eaAny valid css color value (#000, rgb(...), rgba(...)). The color of the border around the story bubble.
bubbleSize96pxValid css size value, except % (10px, 10vw...). The size of the avatar aka bubble.
hideTitlefalseBoolean. Hides the bubble title if true (default false)
animatedBubblefalseBoolean. Makes the bubbles as gif animation.
wrapfalseBoolean. Add styles which allow a horizontal series of bubbles to wrap to new lines, when the screen is narrow.
scrolltrueBoolean. Show a scroll bar when stories do not fit in the page or parent container.
isFullHeightMobiletrueBoolean. Add styles which allow making a full-screen popup. It's work only on mobile phone
showPlayIconfalseBoolean. Add Play icon inside the bubbles
playIconUrlundefinedOptional string, will show the given icon in the play bubble.
aligncenterString. Valid values 'left', 'right', 'end', 'start', 'center' . It sets alignment for bubbles horizontally
autoSeguefalseBoolean. Enable or disable the transition to next story in the end
fullscreenPlayerfalseBoolean. Set to true to remove all margins from the player when opened in popup mode
noShadefalseBoolean. Set to true to not apply a page background shade when the player is opened in popup mode
titleFontSize12pxValid css size value. By default, a size is selected based on bubbleSize between 12px and 36px.
titleFontColorblackAny valid css color value (#000, rgb(...), rgba(...)). The color of the bubble title text.
titleFontFamilyundefinedValid css font family name. Inherited from the document by default.
titleFontWeightundefinedValid css font weight. Inherited from the document by default.
inheritTextFontFamilyfalseBoolean. Whether to inherit the font family from the page for bubble titles.
inheritTextStylesfalseBoolean. Whether to inherit font family, font size, font weight and color from the page for bubble titles.
zIndex2000000Number. Sets the priority of the player above other content when open.
on.loadedfunctionFunction. Called when all Bubbles have loaded.
on.closefunctionFunction. Called when all popups are closed.
stories[]Required for inline javascript. Array. Data of stories.
stories[0...n].idRequired. String. Identifire of story.
stories[0...n].titleString. Change title text of specific story.
stories[0...n].thumbnailUrlString. Overrides the image used for the bubble.
stories[0...n].bubbleSrcDeprecated. Alias of thumbnailUrl.
playerOptions{}Object. Provides options to the player when opening. See Player Options for details.

Events

on.loaded is called with a controller as it's first parameter. See Opening Stories Programmatically for more information.

Embedded player

Creates a Player and returns an interface for managing it, and for listening to its events.

Player Options

optiondefaultdescription
containerQuery Selector for HTMLElement. Container where the player will be inserted.
storyIdRequired. String. The key of the story.
autoStartfalseBoolean. Add autoplay attributes to the video.
autoStartWithSoundfalseBoolean. Add autoplay attributes to the video, and don't mute the video at the same time.
loopfalseBoolean. Add loop function to video.
roundedCornerstrueBoolean. Enable or disable rounded corners to player element.
shadowtrueBoolean. Enable or disable shadow on the player element.
widthundefinedNumber. Set player width. If height is not defined it will calculate automaticaly using an aspect ratio of 16:9.
heightundefinedNumber. Set player height. If width is not defined it will calculate automaticaly using an aspect ratio of 16:9.
checkViewPorttrueBoolean. Enable functionality which pause player if it outside of screen view area.
playButtontrueBoolean. Enable or disable play button.
transcriptButtonfalseBoolean. Enable or disable button to download a transcript. Only shown if applicable.
savePositiontrueBoolean. Enable or disable save last watched chapter. It needs to confirm policy by user
useMediaProxyfalseBoolean. Enable the use of a reverse proxy hosted by Gobi for media content.
on[]Array. Data of event listener
on.videoPlayfunctionCalled when the video plays.
on.videoPausefunctionCalled when the video pauses.
on.videoCompletefunctionCalled when the video completes.
on.clickPreviousfunctionCalled when changing to the previous chapter.
on.clickNextfunctionCalled when changing to the next chapter.
on.clipChangefunctionCalled when a chapter changes.
on.newIterationfunctionCalled when the story loops back to the beginning (requires loop to be true).
on.errorfunctionCalled when an error occurs.
on.loadedfunctionCalled when the video is loaded.

Events

All events are called with the relevant chapter index as the first parameter.

Methods

You can destroy the Gobi Player to free up resources:

var player = new gobi.Player({
  container: '#player-container',
  storyId: 'story-key',
});

player.destroy();

Opening Gobi Stories Programmatically

Several functions allow you to open story popups programmatically, either immediately or using a controller passed to a callback:

FunctionDescription
openPopup(id, options)Opens a story immediately without preloading
renderPopups(options, callback)Preloads stories for opening later
renderBubbles(options, callback)Displays bubbles that can be opened later
discover(options, callback)Finds and renders gobi-stories embeds

Options are the same as Bubble Options.

The functions renderPopups() and renderBubbles() require a container to be specified in options. The discover() function required elements in the dom with the class gobi-stories to create bubbles or gobi-popups to create popups.

The function openPopup() does not require an element to be provided.

The callback's only argument is a controller with the properties:

PropertyTypeDescription
storyIdsstring[]An array of loaded story ids
openPopup(id)functionOpens a popup story player for the given story id

Note: The on.loaded bubble option is also passed a controller as it's first argument.

You can open a popup story player at any time with openPopup():

gobi.openPopup('story-id');

Important: In many browsers playing a video with sound requires at least one user interaction that starts a video with sound. Therefore openPopup() must either be called by a user interaction event (such as click), or after this requirement has been met some other way, otherwise the video may fail to start.

To preload story data and poster images before opening a popup, call renderPopups() and use the controller passed to the callback to open the story. This may provide a smoother experience, particularly on slower internet connections.

gobi.renderPopups({ stories: [{ id: 'story-id' }] }, controller => {
  controller.openPopup('story-id');
});

If you want to show bubbles on your page and want to open them programmatically, you can use renderBubbles to create the bubbles and get the controller with a callback:

gobi.renderBubbles({ container: '#gobi-container', stories: [{ id: 'story-id' }] }, controller => {
  controller.openPopup('story-id');
});

If you are using gobi.discover() to create your bubbles, you can get a controller using the second parameter, and use it later:

let gobiController;

gobi.discover({}, controller => {
  gobiController = controller;
});

// You can now use gobiController to open stories, for example with onClick handlers.

版本与发布记录

@gobistories/gobi-web-integration 共发布 274 个版本,首次发布于 2019/04/09;过去 12 个月发布了 6 个版本。

版本发布日期距今
6.19.13latest2026/10/161 个月前
6.19.122026/09/171 个月前
6.19.112026/09/171 个月前
6.19.82025/12/0911 个月前
6.19.72025/12/0811 个月前
6.19.62025/12/0411 个月前

其他发布通道:beta → 6.14.0-b。

关于 @gobistories/gobi-web-integration 的常见问题

@gobistories/gobi-web-integration 是什么?

This library will let you put your Gobi stories on your site.

如何安装 @gobistories/gobi-web-integration?

在项目目录运行 npm install @gobistories/gobi-web-integration,或使用 pnpm add / yarn add / bun add。

@gobistories/gobi-web-integration 支持 TypeScript 吗?

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

@gobistories/gobi-web-integration 支持 ESM 还是 CommonJS?

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

@gobistories/gobi-web-integration 可以商用吗?

@gobistories/gobi-web-integration 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@gobistories/gobi-web-integration 的下载量有多少?

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

@gobistories/gobi-web-integration 还在维护吗?

最新版本 6.19.13 发布于 2026/10/16(1 个月前);至今共发布 274 个版本,其中过去 12 个月发布了 6 个;首次发布于 2019/04/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。