open-index/open-npm huggingface dataset:
npm package: @lingames/clever-sdk
Description: Clever SDK
Latest version: 0.1.22

灵镜游戏 SDK
==========


## Cocos

### 动态判断法

使用 `createSdk` 函数动态派发 SDK 实现

```ts
import {createSdk} from "@lingames/clever-sdk/src";
const sdk = await createSdk({...})

Global["mySdk"] = sdk
```


### 静态编译法

在 Cocos 中创建 `GAME_PLATFORM` 宏, 静态派发 SDK 实现

![Image](https://github.com/user-attachments/assets/27473126-5d59-45a3-9be4-de95a5073500)


```ts
export async function createSdk(config: DynamicSdkConfig): Promise<CleverSdk> {
    console.log('my sdk create:', GAME_PLATFORM, config.game_id, typeof (config.wx));
    if (GAME_PLATFORM == 'WECHAT_GAME') {
        let sdk = new WeChatSdk(GAME_PLATFORM, config.sdk_url, config.sdk_key, config.game_id);
        await sdk.initialize({wx: window.wx});
        return sdk
    }
    if (GAME_PLATFORM == 'douyingame') {
        return new WeChatSdk(GAME_PLATFORM, config.sdk_url, config.sdk_key, config.game_id);
    }
    if (GAME_PLATFORM == 'kuaishou') {
        return new KuaiShouSdk(GAME_PLATFORM, config.sdk_url, config.sdk_key, config.game_id);
    }
    if (GAME_PLATFORM == 'bilibili') {
        return new BilibiliSdk(GAME_PLATFORM, config.sdk_url, config.sdk_key, config.game_id);
    }
    if (GAME_PLATFORM == 'oppo') {
        return new OppoSdk(GAME_PLATFORM, config.sdk_url, config.sdk_key, config.game_id);
    }
    if (GAME_PLATFORM == 'google') {
        let sdk = new AdSenseSdk(GAME_PLATFORM, config.sdk_url, config.sdk_key, config.game_id);
        await sdk.initialize({adSenseId: config.adSenseId});
        return sdk
    }

    return new BrowserSdk(GAME_PLATFORM, config.sdk_url, config.sdk_key, config.game_id);
}
```
npm package: @lingames/clever-tracer
Description: Clever Engine Tracer
Latest version: 0.0.3

灵境引擎追踪器
===========

在网页上自动生成如下映射代码:

```ts
import {CeTracer} from "@lingames/clever-tracer";

/**
 See {@link https://api.clever-tracer.com/v1/report/version events}.
 */
export enum MyGameChannels {
    WECHAT = 'hash-y',
    DOUYIN = 'hash-y',
}

/**
 See {@link https://api.clever-tracer.com/v1/report/version events}.
 */
export enum MyGameVersions {
    V1_0_0 = 'hash-xx',
    V1_1_0 = 'hash-yy',
    V2_0_0 = 'hash-zz',
}

/**
 See {@link https://api.clever-tracer.com/v1/report/version events}.
 */
export enum MyGameEvents {
    LOGIN_IN = 'hash-xxx',
    RECHARGE = 'hash-yyy',
    LOGIN_OUT = 'hash-zzz',
}

export class MyGameTracer extends CeTracer {
    public override channel?: MyGameChannels | string = undefined
    public override version?: MyGameVersions | string = undefined
    reportLoginIn(custom?: any) {
        this.callEventReport(MyGameEvents.LOGIN_IN, custom)
    }
    reportRecharge(custom?: any) {
        this.callEventReport(MyGameEvents.RECHARGE, custom)
    }
    reportLoginOut(custom?: any) {
        this.callEventReport(MyGameEvents.LOGIN_OUT, custom)
    }
}
```

使用时只需初始化并调用 tracer 上的函数即可

```ts
const tracer = new MyGameTracer()
// 使用宏或者环境变量设置渠道和版本
tracer.version = MyGameVersions.V1_0_0
tracer.channel = MyGameChannels.WECHAT
// 报告充值事件
tracer.reportRecharge({money: 100})
```
npm package: @lingames/clever-tracer-taro
Description: Clever Engine Tracer
Latest version: 0.0.0

灵境引擎 Taro 追踪器
=================

在网页上自动生成如下映射代码:

```ts
import {CeTracer} from "@lingames/clever-tracer-taro";

/**
 See {@link https://api.clever-tracer.com/v1/report/version events}.
 */
export enum MyGameChannels {
    WECHAT = 'hash-y',
    DOUYIN = 'hash-y',
}

/**
 See {@link https://api.clever-tracer.com/v1/report/version events}.
 */
export enum MyGameVersions {
    V1_0_0 = 'hash-xx',
    V1_1_0 = 'hash-yy',
    V2_0_0 = 'hash-zz',
}

/**
 See {@link https://api.clever-tracer.com/v1/report/version events}.
 */
export enum MyGameEvents {
    LOGIN_IN = 'hash-xxx',
    RECHARGE = 'hash-yyy',
    LOGIN_OUT = 'hash-zzz',
}

export class MyGameTracer extends CeTracer {
    public override channel?: MyGameChannels | string = undefined
    public override version?: MyGameVersions | string = undefined
    reportLoginIn(custom?: any) {
        this.callEventReport(MyGameEvents.LOGIN_IN, custom)
    }
    reportRecharge(custom?: any) {
        this.callEventReport(MyGameEvents.RECHARGE, custom)
    }
    reportLoginOut(custom?: any) {
        this.callEventReport(MyGameEvents.LOGIN_OUT, custom)
    }
}
```

使用时只需初始化并调用 tracer 上的函数即可

```ts
const tracer = new MyGameTracer()
// 使用宏或者环境变量设置渠道和版本
tracer.version = MyGameVersions.V1_0_0
tracer.channel = MyGameChannels.WECHAT
// 报告充值事件
tracer.reportRecharge({money: 100})
```