1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| import TDAnalytics from './TDAnalytics';
const { ccclass, property } = cc._decorator;
@ccclass export default class GameStart extends cc.Component {
onLoad() { TDAnalytics.loadScript(() => { cc.log('TalkingData SDK loaded'); }, (err) => { cc.error('Failed to load TalkingData:', err); });
this.initGame(); }
initGame() { }
onLoginSuccess(userInfo) { TDAnalytics.initUser({ accountId: userInfo.id, accountName: userInfo.name, accountType: userInfo.isGuest ? 1 : 2, age: userInfo.age || 0, gender: userInfo.gender === 'male' ? 1 : 2, level: userInfo.level || 1, gameServer: userInfo.server || 's1' }); }
onLevelStart(levelId) { TDAnalytics.onLevelBegin(levelId, { levelId: levelId, difficulty: 'normal' }); }
onLevelComplete(levelId, score) { TDAnalytics.onLevelComplete(levelId, { levelId: levelId, score: score }); }
onPurchase(itemInfo) { TDAnalytics.onPay({ userId: itemInfo.userId, orderId: itemInfo.orderId, amount: itemInfo.price, currency: 'CNY', payType: itemInfo.payMethod, itemId: itemInfo.itemId, itemCount: itemInfo.count }); }
onButtonClick(buttonName) { TDAnalytics.onEvent('button_click', { button: buttonName, scene: cc.director.getScene().name }); } }
|