Refer to Get SDK to import solarengine-unity-sdk.unitypackage.
Refer to the Tencent Mini Game Ads SDK Integration Document to download the Tencent Mini Game Ads SDK. Place the index.js file into the wechat-default folder. The wechat-default folder is generally located at WX-WASM-SDK-V2\Runtime\wechat-default.
Open the game.js file in the same directory as index.js and add the following two lines of code:
Note: You must first integrate the Unity to WeChat Mini Game plugin open-sourced by the WeChat team for this file to exist.
import { SDK } from './index.js';
GameGlobal.SDK=SDK;
SolarEngine.Analytics.preInitSeSdk("appkey");public static void initSeSdk(string appKey, SEConfig seConfig)Parameter Description
| Parameter | Description | Type | Required |
|---|---|---|---|
| appkey | The appkey obtained in Step 1 | String | Yes |
| seConfig | SDK configuration item | SEConfig | Yes |
SEConfig Parameter Description
| Parameter | Description | Type | Required |
|---|---|---|---|
| logEnabled | Whether the console prints SDK logs (Default false) | bool | No |
| isDebugModel | Whether to enable the debugging mode (Default false) | bool | No |
| miniGameInitParams | Mini Game related configurations. | MiniGameInitParams | Required if initializing the Tencent Ads SDK. |
MiniGameInitParams Parameter Description
| Parameter Name | Description | Type | Required |
|---|---|---|---|
| openid | Mini Game Open ID (If not provided, SDK will obtain automatically, but you must fill in the AppID and AppSecret in the SE backend app management and configure them in the Douyin/WeChat backend. See Backend Configuration). | string | No |
| anonymous_openid | Mini Game anonymous_openid. If not provided, the SDK will get the current anonymous_openid. (Same as openid, requires AppID and AppSecret in SE backend). This parameter is for Douyin only. | string | No |
| unionid | Mini Game unionid. | string | No |
| isInitTencentAdvertisingGameSDK | Whether to initialize the Tencent Mini Game Ads SDK. Default is false (disabled). | bool | Required if initializing the Tencent Ads SDK. |
| reportingToTencentSdk | Report events to Tencent. Required if Tencent Ads SDK is initialized. 1: Full reporting 2: Partial reporting 3: No reporting | int | No |
| tencentAdvertisingGameSDKInitParams | Required parameters for initializing the Tencent Mini Game Ads SDK. | TencentAdvertisingGameSDKInitParams | Required if initializing the Tencent Ads SDK. |
TencentAdvertisingGameSDKInitParams Parameter Description
| Parameter | Type | Required | Description |
|---|---|---|---|
| user_action_set_id | int | Yes | Data Source ID |
| secret_key | string | Yes | Encryption key |
| appid | string | Yes | WeChat Mini Game APPID (starts with wx) |
| tencentSdkIsAutoTrack | bool | No | Whether the Tencent SDK automatically collects data. Default true. |
Code Example
SEConfig seConfig = new SEConfig();
MiniGameInitParams initParams = new MiniGameInitParams();
initParams.anonymous_openid = "your anonymous_openid";
initParams.unionid = "your unionid";
initParams.openid = "your openid";
seConfig.logEnabled = true;
TencentAdvertisingGameSDKInitParams tencentAdvertisingGameSDKInitParams = new TencentAdvertisingGameSDKInitParams();
tencentAdvertisingGameSDKInitParams.user_action_set_id = user_action_set_id;
tencentAdvertisingGameSDKInitParams.secret_key = "secret_key";
tencentAdvertisingGameSDKInitParams.appid = "appid";
initParams.tencentAdvertisingGameSDKInitParams = tencentAdvertisingGameSDKInitParams;
initParams.reportingToTencentSdk = 1;
initParams.isInitTencentAdvertisingGameSDK = true;
seConfig.miniGameInitParams = initParams;
SolarEngine.Analytics.initSeSdk("appkey", seConfig);
It shall be triggered as users make a purchase.
public static void trackPurchase(ProductsAttributes attributes)ProductsAttributes Parameter Description:
| Parameter | Description | Type | Required |
|---|---|---|---|
| reportingToTencentSdk | Report events to Tencent. Required if Tencent Ads SDK is initialized. 1: Full reporting 2: Partial reporting 3: No reporting | int | Yes |
| order_id | The order ID generated by the system for this purchase. | string | No |
| pay_amount | The amount paid for this purchase, Unit Yuan. | double | Yes |
| currency_type | The currency type of the payment, following the ISO 4217 standard (e.g., CNY, USD). | string | Yes |
| pay_type | The payment method, e.g., alipay, weixin, applepay, paypal. | string | No |
| product_id | The ID of the purchased product. | string | No |
| product_name | The name of the product. | string | No |
| product_num | The quantity of the product purchased. | Int | No |
| paystatus | Payment status. Success: Success Fail: Fail Restored: Restored | PayStatus | Yes |
| fail_reason | The reason for payment failure. | string | No |
| customProperties | Custom properties. | Dictionary | No |
Note: The fail_reason parameter is only passed when the paystatus is Fail. For other statuses, pass an empty string "".
Code Example:
ProductsAttributes productsAttributes = new ProductsAttributes();
productsAttributes.product_name = "product_name";
productsAttributes.product_id = "product_id";
productsAttributes.product_num = 8;
productsAttributes.currency_type = "CNY";
productsAttributes.order_id = "order_id";
productsAttributes.fail_reason = "fail_reason";
productsAttributes.paystatus = PayStatus.Success;
productsAttributes.pay_type = "wechat";
productsAttributes.pay_amount = 9.9;
productsAttributes.customProperties = getCustomProperties();
productsAttributes.reportingToTencentSdk = 1;
SolarEngine.Analytics.trackPurchase(productsAttributes);
It shall be triggered as users register.
Method Example:
public static void trackRegister(RegisterAttributes attributes)RegisterAttributes Parameter Description:
| Parameter | Description | Type | Required |
|---|---|---|---|
| reportingToTencentSdk | Report events to Tencent. Required if Tencent Ads SDK is initialized. 1: Full reporting 2: Partial reporting 3: No reporting | int | Yes |
| register_type | The registration type, e.g., "WeChat", "QQ", or other custom values. | string | Yes, max 32 characters |
| register_status | The registration status, e.g., "success". | string | No |
| customProperties | Custom properties. | Dictionary | No |
Code Example :
RegisterAttributes registerAttributes = new RegisterAttributes();
registerAttributes.register_type = "QQ_test";
registerAttributes.register_status = "success";
registerAttributes.customProperties = getCustomProperties();
registerAttributes.reportingToTencentSdk = 1;
SolarEngine.Analytics.trackRegister(registerAttributes);
Triggered when a previously registered Mini Game user returns after becoming inactive. The recommended inactivity thresholds are 7, 14, or 30 days. However, any custom N (days) is supported. The corresponding _event_name is _mpReActive.
Method Example:
public static void trackReActive(ReActiveAttributes attributes)ReActiveAttributes Parameter Description:
| Parameter | Description | Type | Required |
|---|---|---|---|
| reportingToTencentSdk | Report events to Tencent. Required if Tencent Ads SDK is initialized. 1: Full reporting 2: Partial reporting 3: No reporting | int | Yes |
| backFlowDay | The number of days of inactivity before re-activation. | int | Yes |
| customProperties | Custom properties. | Dictionary | No |
Code Example:
ReActiveAttributes registerData = new ReActiveAttributes
{
reportingToTencentSdk = 1,
backFlowDay = 7,
customProperties = new Dictionary<string, object> { { "one", "1" } }
};
SolarEngine.Analytics.trackReActive(registerData);
Triggered when a user adds a Mini Game to their wishlist, including adding to favorites, adding to "My Mini Games," adding to the home screen, or any custom wishlist logic defined by developers. The _event_name is _mpAddToWishlist.
public static void trackAddToWishlist(AddToWishlistAttributes attributes)AddToWishlistAttributes Parameter Description:
| Parameter Name | Description | Type | Required |
|---|---|---|---|
| reportingToTencentSdk | Report events to Tencent. Required if Tencent Ads SDK is initialized. 1: Full reporting 2: Partial reporting 3: No reporting | int | Yes |
| addToWishlistType | The type of "add to wishlist". Optional enum values: default / my (add to my mini programs) / desktop (add to desktop) / others. | string | Yes |
| customProperties | Custom properties. | Dictionary | No |
Code Example:
AddToWishlistAttributes addToWishlistData = new AddToWishlistAttributes
{
reportingToTencentSdk = 1,
addToWishlistType = SolarEngine.Analytics.WishlistType_MY,
customProperties = new Dictionary<string, object> { { "one", "1" } }
};
SolarEngine.Analytics.trackAddToWishlist(addToWishlistData);
Triggered when a user shares a Mini Game. Distinguish between "Share to Friend" and "Share to Moments."
public static void trackShare(ShareAttributes attributes)ShareAttributes Parameter Description:
| Parameter Name | Description | Type | Required |
|---|---|---|---|
| reportingToTencentSdk | Report events to Tencent. Required if Tencent Ads SDK is initialized. 1: Full reporting 2: Partial reporting 3: No reporting | int | Yes |
| mpShareTarget | Share Type (Enum values): · Forward to Friend (APP_MESSAGE) · Share to Moments (TIME_LINE) | int | Yes |
| customProperties | Custom properties | Dictionary | No |
Code Example:
// 1. Share to friend
WX.OnShareAppMessage(() =>
{
ShareAttributes shareData = new ShareAttributes
{
reportingToTencentSdk = 1,
mpShareTarget = SolarEngine.Analytics.ShareTarget_APP_MESSAGE,
customProperties = new Dictionary<string, object> { { "one", "1" } }
};
SolarEngine.Analytics.trackShare(shareData);
});
// 2. Share to Moments
WX.OnShareTimeline((x) =>
{
ShareAttributes shareData = new ShareAttributes
{
reportingToTencentSdk = 1,
mpShareTarget = SolarEngine.Analytics.ShareTarget_TIME_LINE,
customProperties = new Dictionary<string, object> { { "one", "1" } }
};
SolarEngine.Analytics.trackShare(shareData);
});
// 3. Report a share event when actively triggering a share (reporting before triggering the share has a higher success rate)
ShareAttributes shareData = new ShareAttributes
{
reportingToTencentSdk = 1,
mpShareTarget = SolarEngine.Analytics.ShareTarget_APP_MESSAGE,
customProperties = new Dictionary<string, object> { { "one", "1" } }
};
SolarEngine.Analytics.trackShare(shareData);
WX.OnShareAppMessage();
Triggered when a user successfully creates a role in the Mini Game. You can add custom parameters related to character creation, such as the character's name.
public static void trackCreateRole(CreateRoleAttributes attributes)CreateRoleAttributes Parameter Description:
| Parameter Name | Description | Type | Required |
|---|---|---|---|
| reportingToTencentSdk | Report events to Tencent. Required if Tencent Ads SDK is initialized. 1: Full reporting 2: Partial reporting 3: No reporting | int | Yes |
| mpRoleName | The name of the role. | string | Yes |
Code Example:
CreateRoleAttributes createRoleData = new CreateRoleAttributes
{
reportingToTencentSdk = 1,
mpRoleName = "role_name",
};
SolarEngine.Analytics.trackCreateRole(createRoleData);Report the TUTORIAL_FINISH event after a user completes the game's new user guide or tutorial level.
public static void trackTutorialFinish(TutorialFinishAttributes attributes)TutorialFinishAttributes Parameter Description:
| Parameter Name | Description | Type | Required |
|---|---|---|---|
| reportingToTencentSdk | Report events to Tencent. Required if Tencent Ads SDK is initialized. 1: Full reporting 2: Partial reporting 3: No reporting | int | Yes |
Code Example:
TutorialFinishAttributes tutorialFinishData = new TutorialFinishAttributes
{
reportingToTencentSdk = 1,
};
SolarEngine.Analytics.trackTutorialFinish(tutorialFinishData);
Report the UPDATE_LEVEL event when a user levels up in the mini game. You can add custom parameters, such as the current game level or energy.
public static void trackUpdateLevel(UpdateLevelAttributes attributes)UpdateLevelAttributes Parameter Description:
| Parameter Name | Description | Type | Required |
|---|---|---|---|
| reportingToTencentSdk | Report events to Tencent. Required if Tencent Ads SDK is initialized. 1: Full reporting 2: Partial reporting 3: No reporting | int | Yes |
| beforeUpgrade | The level before the upgrade. | int | Yes |
| afterUpgrade | The level after the upgrade. | int | Yes |
| customProperties | Custom properties. | Dictionary<string, object> | No |
Code Example:
UpdateLevelAttributes updateLevelData = new UpdateLevelAttributes
{
reportingToTencentSdk = 1,
beforeUpgrade = 10,
afterUpgrade = 20,
customProperties = new Dictionary<string, object> { { "one", "1" } }
};
SolarEngine.Analytics.trackUpdateLevel(updateLevelData);
Report this event when a user browses the mall page within the mini game.
public static void trackViewContentMall(ViewContentMallAttributes attributes)ViewContentMallAttributes Parameter Description:
| Parameter Name | Description | Type | Required |
|---|---|---|---|
| reportingToTencentSdk | Report events to Tencent. Required if Tencent Ads SDK is initialized. 1: Full reporting 2: Partial reporting 3: No reporting | int | Yes |
| customProperties | Custom properties. | Dictionary | No |
Code Example:
ViewContentMallAttributes viewContentMallData = new ViewContentMallAttributes
{
reportingToTencentSdk = 1,
customProperties = new Dictionary<string, object> { { "one", "1" } }
};
SolarEngine.Analytics.trackViewContentMall(viewContentMallData);
Report this event when a user browses a game activity page within the mini game.
public static void trackViewContentActivity(ViewContentActivitAttributes attributes)ViewContentActivitAttributes Parameter Description:
| Parameter Name | Description | Type | Required |
|---|---|---|---|
| reportingToTencentSdk | Report events to Tencent. Required if Tencent Ads SDK is initialized. 1: Full reporting 2: Partial reporting 3: No reporting | int | Yes |
| customProperties | Custom properties. | Dictionary | No |
Code Example:
ViewContentActivitAttributes viewContentActivityData = new ViewContentActivitAttributes
{
reportingToTencentSdk = 1,
customProperties = new Dictionary<string, object> { { "one", "1" } }
};
SolarEngine.Analytics.trackViewContentActivity(viewContentActivityData);
reportingToTencentSdkYou can configure the reportingToTencentSdk field separately for the "Launch Event" and each "Predefined Event". Here are the currently supported predefined events (see above for details):
Note: It is recommended to actively report the events listed above. For these events, you can configure the reportingToTencentSdk field for each one individually for more granular control over data callbacks.
ReportingToTencentSdk Field Options:reportingToTencentSdk field to 1.reportingToTencentSdk field to 2. Note: After the Tencent Ads API attribution is deprecated, attribution via SolarEngine will no longer be possible. Please use Option 1.reportingToTencentSdk field to 3.Note: Channels other than Tencent Ads are still attributed by SolarEngine and reported via API. You do not need to make additional configurations in the SDK for these channels.
How to determine if an event was successfully reported to Tencent?
You can check the return value of the interface https://api.datanexus.qq.com/data-nexus-cgi/miniprogram. If code=0, the report was successful.
