3232
3333public class UniSensorsAnalyticsModule extends UniDestroyableModule {
3434
35- public static final String VERSION = "0.0.2 " ;
35+ public static final String VERSION = "0.0.3 " ;
3636
3737 private static final String MODULE_NAME = "UniSensorsAnalyticsModule" ;
3838 private static final String LOG_TAG = "SA.UniModule" ;
@@ -52,6 +52,21 @@ public void track(String eventName, JSONObject properties) {
5252 }
5353 }
5454
55+ /**
56+ * 调用 trackViewScreen 接口,触发页面浏览事件
57+ *
58+ * @param url url
59+ * @param properties 事件的属性
60+ */
61+ @ UniJSMethod ()
62+ public void trackViewScreen (String url , JSONObject properties ) {
63+ try {
64+ SensorsDataAPI .sharedInstance ().trackViewScreen (url , UniPropertyManager .mergeProperty (JSONUtils .convertToJSONObject (properties )));
65+ } catch (Exception e ) {
66+ Log .i (LOG_TAG , e .getMessage ());
67+ }
68+ }
69+
5570 /**
5671 * 设置当前 serverUrl
5772 *
@@ -494,6 +509,217 @@ public void profileDelete() {
494509 }
495510 }
496511
512+ /**
513+ * 保存用户推送 ID 到用户表
514+ *
515+ * @param pushTypeKey 属性名称(例如 jgId)
516+ * @param pushId 推送 ID
517+ * 使用 profilePushId("jgId",JPushInterface.getRegistrationID(this))
518+ */
519+ @ UniJSMethod
520+ public void profilePushId (String pushTypeKey , String pushId ) {
521+ try {
522+ SensorsDataAPI .sharedInstance ().profilePushId (pushTypeKey , pushId );
523+ } catch (Exception e ) {
524+ Log .i (LOG_TAG , e .getMessage ());
525+ }
526+ }
527+
528+ /**
529+ * 删除用户设置的 pushId
530+ *
531+ * @param pushTypeKey 属性名称(例如 jgId)
532+ */
533+ @ UniJSMethod
534+ public void profileUnsetPushId (String pushTypeKey ) {
535+ try {
536+ SensorsDataAPI .sharedInstance ().profileUnsetPushId (pushTypeKey );
537+ } catch (Exception e ) {
538+ Log .i (LOG_TAG , e .getMessage ());
539+ }
540+ }
541+
542+ /**
543+ * 初始化事件的计时器,计时单位为秒。
544+ *
545+ * @param eventName 事件的名称
546+ * @return 交叉计时的事件名称
547+ */
548+ @ UniJSMethod (uiThread = false )
549+ public String trackTimerStart (String eventName ) {
550+ try {
551+ return SensorsDataAPI .sharedInstance ().trackTimerStart (eventName );
552+ } catch (Exception e ) {
553+ Log .i (LOG_TAG , e .getMessage ());
554+ }
555+ return null ;
556+ }
557+
558+ /**
559+ * 暂停事件计时器,计时单位为秒。
560+ *
561+ * @param eventName 事件的名称
562+ */
563+ @ UniJSMethod ()
564+ public void trackTimerPause (String eventName ) {
565+ try {
566+ SensorsDataAPI .sharedInstance ().trackTimerPause (eventName );
567+ } catch (Exception e ) {
568+ Log .i (LOG_TAG , e .getMessage ());
569+ }
570+ }
571+
572+ /**
573+ * 恢复事件计时器,计时单位为秒。
574+ *
575+ * @param eventName 事件的名称
576+ */
577+ @ UniJSMethod ()
578+ public void trackTimerResume (String eventName ) {
579+ try {
580+ SensorsDataAPI .sharedInstance ().trackTimerResume (eventName );
581+ } catch (Exception e ) {
582+ Log .i (LOG_TAG , e .getMessage ());
583+ }
584+ }
585+
586+ /**
587+ * 停止事件计时器
588+ *
589+ * @param eventName 事件的名称,或者交叉计算场景时 trackTimerStart 的返回值
590+ * @param properties 事件的属性
591+ */
592+ @ UniJSMethod ()
593+ public void trackTimerEnd (String eventName , JSONObject properties ) {
594+ try {
595+ SensorsDataAPI .sharedInstance ().trackTimerEnd (eventName , UniPropertyManager .mergeProperty (JSONUtils .convertToJSONObject (properties )));
596+ } catch (Exception e ) {
597+ Log .i (LOG_TAG , e .getMessage ());
598+ }
599+ }
600+
601+ /**
602+ * 删除事件的计时器
603+ *
604+ * @param eventName 事件名称
605+ */
606+ @ UniJSMethod ()
607+ public void removeTimer (String eventName ) {
608+ try {
609+ SensorsDataAPI .sharedInstance ().removeTimer (eventName );
610+ } catch (Exception e ) {
611+ Log .i (LOG_TAG , e .getMessage ());
612+ }
613+ }
614+
615+ /**
616+ * 清除所有事件计时器
617+ */
618+ @ UniJSMethod
619+ public void clearTrackTimer () {
620+ try {
621+ SensorsDataAPI .sharedInstance ().clearTrackTimer ();
622+ } catch (Exception e ) {
623+ Log .i (LOG_TAG , e .getMessage ());
624+ }
625+ }
626+
627+ /**
628+ * 获取事件公共属性
629+ *
630+ * @return 当前所有 Super 属性
631+ */
632+ @ UniJSMethod (uiThread = false )
633+ public JSONObject getSuperProperties () {
634+ try {
635+ return JSONUtils .convertToFastJson (SensorsDataAPI .sharedInstance ().getSuperProperties ());
636+ } catch (Exception e ) {
637+ Log .i (LOG_TAG , e .getMessage ());
638+ }
639+ return null ;
640+ }
641+
642+ /**
643+ * DeepLink 是否采集设备信息
644+ *
645+ * @param enable 是否采集设备信息 true:是 false:否
646+ */
647+ @ UniJSMethod
648+ public void enableDeepLinkInstallSource (boolean enable ) {
649+ try {
650+ SensorsDataAPI .sharedInstance ().enableDeepLinkInstallSource (enable );
651+ } catch (Exception e ) {
652+ Log .i (LOG_TAG , e .getMessage ());
653+ }
654+ }
655+
656+ /**
657+ * 记录 $AppDeepLinkLaunch 事件
658+ *
659+ * @param deepLinkUrl 唤起应用的 DeepLink 链接
660+ * @param oaid oaid 非必填
661+ */
662+ @ UniJSMethod
663+ public void trackDeepLinkLaunch (String deepLinkUrl , String oaid ) {
664+ try {
665+ SensorsDataAPI .sharedInstance ().trackDeepLinkLaunch (deepLinkUrl , oaid );
666+ } catch (Exception e ) {
667+ Log .i (LOG_TAG , e .getMessage ());
668+ }
669+ }
670+
671+ /**
672+ * 开启/关闭采集屏幕方向
673+ *
674+ * @param enable true:开启 false:关闭
675+ */
676+ @ UniJSMethod
677+ public void enableTrackScreenOrientation (boolean enable ) {
678+ try {
679+ SensorsDataAPI .sharedInstance ().enableTrackScreenOrientation (enable );
680+ } catch (Exception e ) {
681+ Log .i (LOG_TAG , e .getMessage ());
682+ }
683+ }
684+
685+ /**
686+ * 恢复采集屏幕方向
687+ */
688+ @ UniJSMethod
689+ public void resumeTrackScreenOrientation () {
690+ try {
691+ SensorsDataAPI .sharedInstance ().resumeTrackScreenOrientation ();
692+ } catch (Exception e ) {
693+ Log .i (LOG_TAG , e .getMessage ());
694+ }
695+ }
696+
697+ /**
698+ * 停止采集屏幕方向
699+ */
700+ @ UniJSMethod
701+ public void stopTrackScreenOrientation () {
702+ try {
703+ SensorsDataAPI .sharedInstance ().stopTrackScreenOrientation ();
704+ } catch (Exception e ) {
705+ Log .i (LOG_TAG , e .getMessage ());
706+ }
707+ }
708+
709+ /**
710+ * 获取当前屏幕方向
711+ *
712+ * @return portrait:竖屏 landscape:横屏
713+ */
714+ @ UniJSMethod (uiThread = false )
715+ public String getScreenOrientation () {
716+ try {
717+ return SensorsDataAPI .sharedInstance ().getScreenOrientation ();
718+ } catch (Exception e ) {
719+ Log .i (LOG_TAG , e .getMessage ());
720+ }
721+ return "" ;
722+ }
497723
498724 @ Override
499725 public void destroy () {
0 commit comments