var ptagent = require('./js/libs/ptagent.js');
注意:SDK采集的数据会发送到https://mp.ptengine.cn,读取相关SDK配置信息是从https://appconfigloader.ptengine.cn获取。
所以需要在配置服务器信息中添加以上两个域名信息,如下截图所示:
示例:ptagent.PtInit(“ug26cpustmfx&5759y4hwcn”, “1.2.0”);
/** * Start PtAgent engine, you should invoke it in onShow() lifecyle function of App, * make sure our module can be inited everytime, even though your app is actived from background mode. * @param ptApp ID: String, you can get it as soon as registered an application in our web management backend. * @param appVersion: String, your mini program version number. */ PtInit: function(ptAppKey, appVersion){ _ptagent_core.init(ptAppKey, appVersion); }
示例:ptagent.PtTrackEvent(“购买”, {“商品名称”:“净化器”,“商品价格”: “2000人民币”,。。。。});
/** * If you want to collect app events by yourself, you can invoke this API * @param eventName: String, this value can't be nil or empty * @param properties: {} or undefined, you can bind some event properties for every event, * if you don't need it, just pass undefined. */ PtTrackEvent: function (eventName, properties){ _ptagent_core.trackEvent(eventName, properties); }
示例:ptagent.PtTrackSharedEventForMiniProgram({“标题”:“…”, “路径”:“…”});
/** * Track the shared event if you need, event name is defined by SDK * you just need to pass the event properties * @param properties: {}, the properties that you want to describe the event */ PtTrackSharedEventForMiniProgram: function (properties) { _ptagent_core.trackSharedEventForMiniProgram(properties); }
示例:ptagent.PtBeginEvent(“页面浏览时长”);
/** * You can invoke this method to mark the begin time for the defined event. * @param eventName: String, this value can't be nil or empty */ PtBeginEvent: function (eventName){ _ptagent_core.beginEvent(eventName); }
示例:ptagent.PtEndEvent(“页面浏览时长”, {“页面名称”:“…”, “页面来源”: “…”});
/** * Mark the end time for defined event, and send event package to server. * You can specific the event properties for yourself at this moment. * @param eventName: String, this value can't be nil or empty, * and must be same with the value passed in PtBeginEvent() * @param properties: {} or undefined. */ PtEndEvent: function(eventName, properties){ _ptagent_core.endEvent(eventName, properties);}
示例:ptagent.PtTrackUserInfo(“138100…”, “182823233”, “abdckdkdjfda”, {“邮件”:“…”,”地址”:“…”});
/** * Track the user info if you need, you can also pass the openid, union id by yourself. * @param userID: String, the account info of your mini program. * @param wxOpenID: String, openid that acquired from weixin. * @param wxUnionID: String, unionid that acquired from weixin. * @param userProfiles: {} or undefined, the other info of the account, such as, email, address... */ PtTrackUserInfo: function(userID, wxOpenID, wxUnionID, userProfiles){ _ptagent_core.trackUserInfo(userID, wxOpenID, wxUnionID, userProfiles); }
示例:ptagent.PtTrackException(“2001”, “购买请求失败”);
/** * If you need to track some error info package, just invoke it. * @param exceptionCode: String, error code that you want to defined. * @param exceptionInfo: String, error or stack/heap info */ PtTrackException: function (exceptionCode, exceptionInfo){ _ptagent_core.trackException(exceptionCode, exceptionInfo); }
示例:ptagent.PtTrackPVForCustomView(“…”, {“页面路径”:“…”, “页面来源”: “…”});
/** * For all the Page containers, we have already collected as "pv" data automatically, * so you DON't need to invoke this API to collect the Page's "pv" data by youself, * otherwise, pv data will be collected twice with the different name for one Page. * But in some cases, you can invoke it to define a value as "pv" based on some bussiness for the other view containers (NOT Page), for example ... * @param pageViewName: String page name, this value can't be empty and nil * @param pageProperties: {} or undefined, you can pass some info as the properties for the Page */ PtTrackPVForCustomView: function (pageViewName, pageProperties){ _ptagent_core.trackPVForCustomView(pageViewName, pageProperties); }
/** * Return PtAgent SDK version */ PtSDKVersion: function(){ return _ptagent_core.getSDKVersion(); }
/** * Enable PtAgent SDK log output. */ PtEnableLogOutput: function(){ _ptagent_core.enableLogOutput(); }