已输入 Google IMA SDK
没有同步装入 Google IMA 的运行时间依赖关系的库 SDK,包括SDK本身的TypeScript类型定义.
关于Google IMA SDK本身的信息,请访问 Google的正式文件。 。 。 .
安装
yarn add @alugha/ima 或者说 npm install --save @alugha/ima
使用量
带有合成加载的脚本类型
承诺和共同JS模块:
const { loadImaSdk, google } = require("@alugha/ima");
loadImaSdk()
.then(ima => {
// Use the IMA SDK like any other typed module
const adDisplayContainer: google.ima.AdDisplayContainer = new ima.AdDisplayContainer(
document.getElementById("ad-container")
);
adDisplayContainer.initialize();
})
.catch(() => {
console.log("SDK could not be loaded. Check your ad blocker!");
});
与 async 编号 : await 和ES2015模块:
import { loadImaSdk, google } from "@alugha/ima";
const example = async () => {
try {
const ima = await loadImaSdk();
// Use the IMA SDK like any other typed module
const adDisplayContainer: google.ima.AdDisplayContainer = new ima.AdDisplayContainer(
document.getElementById("ad-container")
);
adDisplayContainer.initialize();
} catch (e) {
console.log("SDK could not be loaded. Check your ad blocker!");
}
};
不同步加载的脚本类型
如果您喜欢使用脚本标记直接加载 SDK, 您仍然可以制作
使用包含类型的定义 types/ima.d.ts。 。 。 .
免责声明
我们没有参与谷歌IMA SDK本身的开发. 这个库也没有以任何方式与Google连接.