Menu

WeChat Mini Games Support Tencent Event Callbacks

Step 1: Import SDK

1.1 Import solarengineSDK

Refer to Get SDK to import solarengine-unity-sdk.unitypackage.

1.2 Import Tencent Mini Game Ads SDK

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.

1.3 Add the code to game.js file

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;

Step 2: Pre-initialization

SolarEngine.Analytics.preInitSeSdk("appkey");

Step 3: Initialization

public static void initSeSdk(string appKey, SEConfig seConfig)

Parameter Description

Parameter DescriptionTypeRequired
appkeyThe appkey obtained in Step 1StringYes
seConfigSDK configuration itemSEConfigYes

SEConfig Parameter Description

Parameter DescriptionTypeRequired
logEnabledWhether the console prints SDK logs (Default false)boolNo
isDebugModelWhether to enable the debugging mode (Default false)boolNo
miniGameInitParamsMini Game related configurations.MiniGameInitParamsRequired if initializing the Tencent Ads SDK.

MiniGameInitParams Parameter Description

Parameter NameDescriptionTypeRequired
openidMini 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).stringNo
anonymous_openidMini 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.stringNo
unionidMini Game unionid.stringNo
isInitTencentAdvertisingGameSDKWhether to initialize the Tencent Mini Game Ads SDK. Default is false (disabled).boolRequired if initializing the Tencent Ads SDK.
reportingToTencentSdkReport events to Tencent. Required if Tencent Ads SDK is initialized.
1: Full reporting
2: Partial reporting
3: No reporting
intNo
tencentAdvertisingGameSDKInitParamsRequired parameters for initializing the Tencent Mini Game Ads SDK.TencentAdvertisingGameSDKInitParamsRequired if initializing the Tencent Ads SDK.


TencentAdvertisingGameSDKInitParams Parameter Description

Parameter TypeRequiredDescription
user_action_set_idintYesData Source ID
secret_keystringYesEncryption key
appidstringYesWeChat Mini Game APPID (starts with wx)
tencentSdkIsAutoTrackboolNoWhether 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);

Step 4: Predefined Events

4.1 In-App Purchase Event

   It shall be triggered as users make a purchase.

public static void trackPurchase(ProductsAttributes attributes)

ProductsAttributes Parameter Description:

Parameter DescriptionTypeRequired
reportingToTencentSdkReport events to Tencent. Required if Tencent Ads SDK is initialized.
1: Full reporting
2: Partial reporting
3: No reporting
intYes
order_idThe order ID generated by the system for this purchase.stringNo
pay_amountThe amount paid for this purchase, Unit Yuan.doubleYes
currency_typeThe currency type of the payment, following the ISO 4217 standard (e.g., CNY, USD).stringYes
pay_typeThe payment method, e.g., alipay, weixin, applepay, paypal.stringNo
product_idThe ID of the purchased product.stringNo
product_nameThe name of the product.stringNo
product_numThe quantity of the product purchased.IntNo
paystatusPayment status.
Success: Success
Fail: Fail
Restored: Restored
PayStatusYes
fail_reasonThe reason for payment failure.stringNo
customPropertiesCustom properties.DictionaryNo
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);

4.2 Registration Event

      It shall be triggered as users register.

Method Example:

public static void trackRegister(RegisterAttributes attributes)

RegisterAttributes Parameter Description:

Parameter DescriptionTypeRequired
reportingToTencentSdkReport events to Tencent. Required if Tencent Ads SDK is initialized.
1: Full reporting
2: Partial reporting
3: No reporting
intYes
register_typeThe registration type, e.g., "WeChat", "QQ", or other custom values.stringYes, max 32 characters
register_statusThe registration status, e.g., "success".stringNo
customPropertiesCustom properties.DictionaryNo

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);

4.3 Re-activation

      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 DescriptionTypeRequired
reportingToTencentSdkReport events to Tencent. Required if Tencent Ads SDK is initialized.
1: Full reporting
2: Partial reporting
3: No reporting
intYes
backFlowDayThe number of days of inactivity before re-activation.intYes
customPropertiesCustom properties.DictionaryNo

Code Example:

ReActiveAttributes registerData = new ReActiveAttributes
{
    reportingToTencentSdk = 1,
    backFlowDay = 7,
    customProperties = new Dictionary<string, object> { { "one", "1" } }
};
SolarEngine.Analytics.trackReActive(registerData);

4.4 Add Mini Game to Wishlist

      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 NameDescriptionTypeRequired
reportingToTencentSdkReport events to Tencent. Required if Tencent Ads SDK is initialized.
1: Full reporting
2: Partial reporting
3: No reporting
intYes
addToWishlistTypeThe type of "add to wishlist". Optional enum values: default / my (add to my mini programs) / desktop (add to desktop) / others.stringYes
customPropertiesCustom properties.DictionaryNo

Code Example:

AddToWishlistAttributes addToWishlistData = new AddToWishlistAttributes
{
    reportingToTencentSdk = 1,
    addToWishlistType = SolarEngine.Analytics.WishlistType_MY,
    customProperties = new Dictionary<string, object> { { "one", "1" } }
};
SolarEngine.Analytics.trackAddToWishlist(addToWishlistData);

4.5 Share Mini Game

      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 NameDescriptionTypeRequired
reportingToTencentSdkReport events to Tencent. Required if Tencent Ads SDK is initialized.
1: Full reporting
2: Partial reporting
3: No reporting
intYes
mpShareTargetShare Type (Enum values):
· Forward to Friend (APP_MESSAGE)
· Share to Moments (TIME_LINE)
intYes
customPropertiesCustom propertiesDictionaryNo

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();

4.6 Create Role

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 NameDescriptionTypeRequired
reportingToTencentSdkReport events to Tencent. Required if Tencent Ads SDK is initialized.
1: Full reporting
2: Partial reporting
3: No reporting
intYes
mpRoleNameThe name of the role.stringYes

Code Example:

CreateRoleAttributes createRoleData = new CreateRoleAttributes
{
    reportingToTencentSdk = 1,
    mpRoleName = "role_name",
};
SolarEngine.Analytics.trackCreateRole(createRoleData);

4.7 Tutorial Finish

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 NameDescriptionTypeRequired
reportingToTencentSdkReport events to Tencent. Required if Tencent Ads SDK is initialized.
1: Full reporting
2: Partial reporting
3: No reporting
intYes

Code Example:

TutorialFinishAttributes tutorialFinishData = new TutorialFinishAttributes
{
    reportingToTencentSdk = 1,
};
SolarEngine.Analytics.trackTutorialFinish(tutorialFinishData);

4.8 Updata Level

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 NameDescriptionTypeRequired
reportingToTencentSdkReport events to Tencent. Required if Tencent Ads SDK is initialized.
1: Full reporting
2: Partial reporting
3: No reporting
intYes
beforeUpgradeThe level before the upgrade.intYes
afterUpgradeThe level after the upgrade.intYes
customPropertiesCustom 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);

4.9 View Mall

Report this event when a user browses the mall page within the mini game.

public static void trackViewContentMall(ViewContentMallAttributes attributes)

ViewContentMallAttributes Parameter Description:

Parameter NameDescriptionTypeRequired
reportingToTencentSdkReport events to Tencent. Required if Tencent Ads SDK is initialized.
1: Full reporting
2: Partial reporting
3: No reporting
intYes
customPropertiesCustom properties.DictionaryNo

Code Example:

ViewContentMallAttributes viewContentMallData = new ViewContentMallAttributes
{
    reportingToTencentSdk = 1,
    customProperties = new Dictionary<string, object> { { "one", "1" } }
};
SolarEngine.Analytics.trackViewContentMall(viewContentMallData);

4.10 View Game Activity

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 NameDescriptionTypeRequired
reportingToTencentSdkReport events to Tencent. Required if Tencent Ads SDK is initialized.
1: Full reporting
2: Partial reporting
3: No reporting
intYes
customPropertiesCustom properties.DictionaryNo

Code Example:

ViewContentActivitAttributes viewContentActivityData = new ViewContentActivitAttributes
{
    reportingToTencentSdk = 1,
    customProperties = new Dictionary<string, object> { { "one", "1" } }
};
SolarEngine.Analytics.trackViewContentActivity(viewContentActivityData);

Reporting Strategy for reportingToTencentSdk

You 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):

  • 4.1 Purchase
  • 4.2 Register
  • 4.3 Re-activation
  • 4.4 Add to Wishlist
  • 4.5 Share
  • 4.6 Create Role
  • 4.7 Tutorial Finish
  • 4.8 Level Up
  • 4.9 View Mall Page
  • 4.10 View Game Activity
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:

  • Option 1 (Recommended): Attribution matching is handled by Tencent Ads. All user event information is reported back to the Tencent Ads platform. Configure the reportingToTencentSdk field to 1.
  • Option 2: Attribution matching is handled by SolarEngine. Only information for users attributed to Tencent Ads is reported back to the Tencent Ads platform. Configure the 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.
  • Option 3 (Not Recommended): Attribution matching is handled by SolarEngine. User information is not reported back to the Tencent Ads platform. Configure the 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.

Q&A

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.

Previous
Douyin Mini Games Support Douyin Cloud
Next
Integration Testing
Last modified: 2026-09-18Powered by