@@ -539,7 +539,7 @@ var IDENTITY_KEY = {
539539 LOGIN : '$identity_login_id'
540540} ;
541541
542- var LIB_VERSION = '1.18.2 ' ;
542+ var LIB_VERSION = '1.18.3 ' ;
543543var LIB_NAME = 'MiniProgram' ;
544544
545545/*
@@ -756,27 +756,10 @@ var store = {
756756 this . _state . identities [ openid_name ] = this . _state . identities [ old_openid_name ] ;
757757 delete this . _state . identities [ old_openid_name ] ;
758758 }
759-
760- // 没有 state.first_id 认为没有登录,或者已经注销
761- // 这部分处理中省去了判断 identities.anonymous_id 和 2.0 匿名ID 是否相等的判断,因为相等就不对 identities.anonymous_id 处理,不相等就将 2.0 的匿名 ID 赋值上去
762- if ( hasOwnProperty$1 . call ( this . _state . identities , '$identity_anonymous_id' ) ) {
763- if ( ! first_id ) {
764- this . _state . identities . $identity_anonymous_id = distinct_id ;
765- } else {
766- this . _state . identities . $identity_anonymous_id = first_id ;
767- }
768- }
769759 } else {
770760 this . _state . identities = { } ;
771761 this . _state . identities . $identity_mp_id = this . getUUID ( ) ;
772- if ( ! first_id ) {
773- // 3.0 identify -> 2.0 identify -> 3.0 更新 anonymous_id
774- this . _state . identities . $identity_anonymous_id = distinct_id ;
775- } else {
776- this . _state . identities . $identity_anonymous_id = first_id ;
777- }
778762 }
779-
780763 // 单独处理 openid
781764 if ( openid ) {
782765 this . _state . identities [ openid_name ] = openid ;
@@ -798,25 +781,11 @@ var store = {
798781 if ( old_login_id_name && hasOwnProperty$1 . call ( this . _state . identities , old_login_id_name ) ) {
799782 if ( this . _state . identities [ old_login_id_name ] !== distinct_id ) {
800783 this . _state . identities [ old_login_id_name ] = distinct_id ;
801- // for (var identitiesprop in this._state.identities) {
802- // if (hasOwnProperty.call(this._state.identities, identitiesprop)) {
803- // if (identitiesprop !== '$identity_mp_id' && identitiesprop !== old_login_id_name) {
804- // delete this._state.identities[identitiesprop];
805- // }
806- // }
807- // }
808784 delIdentitiesProp ( old_login_id_name ) ;
809785 this . _state . history_login_id . value = distinct_id ;
810786 }
811787 } else {
812788 this . _state . identities [ IDENTITY_KEY . LOGIN ] = distinct_id ;
813- // for (var identitiesprop in this._state.identities) {
814- // if (hasOwnProperty.call(this._state.identities, identitiesprop)) {
815- // if (identitiesprop !== '$identity_mp_id' && identitiesprop !== IDENTITY_KEY.LOGIN) {
816- // delete this._state.identities[identitiesprop];
817- // }
818- // }
819- // }
820789 delIdentitiesProp ( IDENTITY_KEY . LOGIN ) ;
821790 this . _state . history_login_id = {
822791 name : IDENTITY_KEY . LOGIN ,
@@ -825,16 +794,6 @@ var store = {
825794 }
826795 } else {
827796 // 处理 3.0 降到 2.0 后调用 logout 但是 3.0 的登录 ID 依旧存在的情况
828- if ( hasOwnProperty$1 . call ( this . _state . identities , '$identity_login_id' ) || hasOwnProperty$1 . call ( this . _state . identities , old_login_id_name ) ) {
829- // for (var identitiesprop in this._state.identities) {
830- // if (hasOwnProperty.call(this._state.identities, identitiesprop)) {
831- // if (identitiesprop !== '$identity_mp_id' && identitiesprop !== '$identity_anonymous_id') {
832- // delete this._state.identities[identitiesprop];
833- // }
834- // }
835- // }
836- delIdentitiesProp ( '$identity_anonymous_id' ) ;
837- }
838797 this . _state . history_login_id = {
839798 name : '' ,
840799 value : ''
@@ -939,11 +898,6 @@ var store = {
939898 case 'logout' :
940899 identities . $identity_mp_id = this . _state . identities . $identity_mp_id ;
941900 break ;
942- case 'identify' :
943- identities = deepCopy ( this . _state . identities ) ;
944- identities . $identity_anonymous_id = params . id ;
945- break ;
946- // donoting
947901 }
948902 this . set ( 'identities' , identities ) ;
949903 } ,
@@ -981,6 +935,7 @@ var store = {
981935 init : function ( ) {
982936 var info = this . getStorage ( ) ;
983937 var flag = 'data:enc;' ;
938+ var uuid = store . getUUID ( ) ;
984939 if ( info ) {
985940 if ( isString ( info ) ) {
986941 //判断是否有加密的字段 有就解密
@@ -998,11 +953,11 @@ var store = {
998953 time . setMinutes ( 59 ) ;
999954 time . setSeconds ( 60 ) ;
1000955 this . set ( {
1001- distinct_id : store . getUUID ( ) ,
956+ distinct_id : uuid ,
1002957 first_visit_time : visit_time ,
1003958 first_visit_day_time : time . getTime ( ) ,
1004959 identities : {
1005- $identity_mp_id : store . getUUID ( )
960+ $identity_mp_id : uuid
1006961 } ,
1007962 history_login_id : {
1008963 name : '' ,
@@ -1025,57 +980,6 @@ var store = {
1025980 }
1026981} ;
1027982
1028- /*
1029- 1030- * @Date : 2022-07-04 11:18:47
1031- * @File :
1032- */
1033-
1034- function registerApp ( obj ) {
1035- if ( isObject ( obj ) && ! isEmptyObject ( obj ) ) {
1036- meta . preset_properties = extend ( meta . preset_properties , obj ) ;
1037- }
1038- }
1039-
1040- function register ( obj ) {
1041- if ( isObject ( obj ) && ! isEmptyObject ( obj ) ) {
1042- store . setProps ( obj ) ;
1043- }
1044- }
1045-
1046- function clearAllRegister ( ) {
1047- store . setProps ( { } , true ) ;
1048- }
1049-
1050- function clearAppRegister ( arr ) {
1051- if ( isArray ( arr ) ) {
1052- each ( meta . preset_properties , function ( value , item ) {
1053- if ( include ( arr , item ) ) {
1054- delete meta . preset_properties [ item ] ;
1055- }
1056- } ) ;
1057- }
1058- }
1059-
1060- /*
1061- 1062- * @Date : 2022-07-05 14:32:00
1063- * @File :
1064- */
1065-
1066- function clearAllProps ( arr ) {
1067- var obj = store . getProps ( ) ;
1068- var props = { } ;
1069- if ( isArray ( arr ) ) {
1070- each ( obj , function ( value , item ) {
1071- if ( ! include ( arr , item ) ) {
1072- props [ item ] = value ;
1073- }
1074- } ) ;
1075- store . setProps ( props , true ) ;
1076- }
1077- }
1078-
1079983/*
10809841081985 * @Date : 2022-08-08 15:54:39
@@ -1765,7 +1669,7 @@ function setSfSource(para, prop) {
17651669 if ( ! isEmptyObject ( para . query ) ) {
17661670 if ( para . query && para . query . _sfs ) {
17671671 prop . $sf_source = para . query . _sfs ;
1768- registerApp ( { $latest_sf_source : prop . $sf_source } ) ;
1672+ sa . registerApp ( { $latest_sf_source : prop . $sf_source } ) ;
17691673 }
17701674 }
17711675}
@@ -1998,10 +1902,10 @@ function setUpperCase(value) {
19981902function setLatestChannel ( channel ) {
19991903 if ( ! isEmptyObject ( channel ) ) {
20001904 if ( includeChannel ( channel , LATEST_SOURCE_CHANNEL ) ) {
2001- clearAppRegister ( LATEST_SOURCE_CHANNEL ) ;
2002- clearAllProps ( LATEST_SOURCE_CHANNEL ) ;
1905+ sa . clearAppRegister ( LATEST_SOURCE_CHANNEL ) ;
1906+ sa . clearAllProps ( LATEST_SOURCE_CHANNEL ) ;
20031907 }
2004- saPara . is_persistent_save . utm ? register ( channel ) : registerApp ( channel ) ;
1908+ saPara . is_persistent_save . utm ? sa . register ( channel ) : sa . registerApp ( channel ) ;
20051909 }
20061910
20071911 function includeChannel ( channel , arr ) {
@@ -2017,10 +1921,10 @@ function setLatestChannel(channel) {
20171921
20181922function setLatestShare ( share ) {
20191923 if ( share . $latest_share_depth || share . $latest_share_distinct_id || share . $latest_share_url_path || share . $latest_share_method ) {
2020- clearAppRegister ( LATEST_SHARE_INFO ) ;
2021- clearAllProps ( LATEST_SHARE_INFO ) ;
1924+ sa . clearAppRegister ( LATEST_SHARE_INFO ) ;
1925+ sa . clearAllProps ( LATEST_SHARE_INFO ) ;
20221926
2023- saPara . is_persistent_save . share ? register ( share ) : registerApp ( share ) ;
1927+ saPara . is_persistent_save . share ? sa . register ( share ) : sa . registerApp ( share ) ;
20241928 }
20251929}
20261930
@@ -2184,7 +2088,7 @@ function setPublicProperties(data) {
21842088 */
21852089function networkStatusChange ( ) {
21862090 wx . onNetworkStatusChange ( function ( res ) {
2187- registerApp ( { $network_type : res . networkType || '' } ) ;
2091+ sa . registerApp ( { $network_type : res . networkType || '' } ) ;
21882092 } ) ;
21892093}
21902094
@@ -3351,7 +3255,7 @@ function checkPrivacyStatus() {
33513255 */
33523256
33533257function apiStaging ( ) {
3354- var saApiList = [ 'setProfile' , 'setOnceProfile' , 'track' , 'quick' , 'incrementProfile' , 'appendProfile' , 'login' , 'logout' , 'registerApp' , 'register' , 'clearAllRegister' , 'clearAllProps' , 'clearAppRegister' , 'bind' , 'unbind' , 'unsetOpenid' , 'setUnionid' , 'unsetUnionid' ] ;
3258+ var saApiList = [ 'setProfile' , 'setOnceProfile' , 'track' , 'quick' , 'incrementProfile' , 'appendProfile' , 'login' , 'logout' , 'registerApp' , 'register' , 'clearAllRegister' , 'clearAllProps' , 'clearAppRegister' , 'bind' , 'unbind' , 'unsetOpenid' , 'setUnionid' , 'unsetUnionid' , 'bindOpenid' , 'unbindOpenid' , 'bindUnionid' , 'unbindUnionid' ] ;
33553259 each ( saApiList , function ( method ) {
33563260 var temp = sa [ method ] ;
33573261 sa [ method ] = function ( ) {
@@ -3370,6 +3274,57 @@ function apiStaging() {
33703274 } ) ;
33713275}
33723276
3277+ /*
3278+ 3279+ * @Date : 2022-07-04 11:18:47
3280+ * @File :
3281+ */
3282+
3283+ function registerApp ( obj ) {
3284+ if ( isObject ( obj ) && ! isEmptyObject ( obj ) ) {
3285+ meta . preset_properties = extend ( meta . preset_properties , obj ) ;
3286+ }
3287+ }
3288+
3289+ function register ( obj ) {
3290+ if ( isObject ( obj ) && ! isEmptyObject ( obj ) ) {
3291+ store . setProps ( obj ) ;
3292+ }
3293+ }
3294+
3295+ function clearAllRegister ( ) {
3296+ store . setProps ( { } , true ) ;
3297+ }
3298+
3299+ function clearAppRegister ( arr ) {
3300+ if ( isArray ( arr ) ) {
3301+ each ( meta . preset_properties , function ( value , item ) {
3302+ if ( include ( arr , item ) ) {
3303+ delete meta . preset_properties [ item ] ;
3304+ }
3305+ } ) ;
3306+ }
3307+ }
3308+
3309+ /*
3310+ 3311+ * @Date : 2022-07-05 14:32:00
3312+ * @File :
3313+ */
3314+
3315+ function clearAllProps ( arr ) {
3316+ var obj = store . getProps ( ) ;
3317+ var props = { } ;
3318+ if ( isArray ( arr ) ) {
3319+ each ( obj , function ( value , item ) {
3320+ if ( ! include ( arr , item ) ) {
3321+ props [ item ] = value ;
3322+ }
3323+ } ) ;
3324+ store . setProps ( props , true ) ;
3325+ }
3326+ }
3327+
33733328var hasOwnProperty$3 = Object . prototype . hasOwnProperty ;
33743329
33753330function setProfile ( p , c ) {
@@ -3461,10 +3416,6 @@ function identify(id, isSave) {
34613416 store . change ( 'distinct_id' , id ) ;
34623417 }
34633418 }
3464- store . identitiesSet ( {
3465- type : 'identify' ,
3466- id : id
3467- } ) ;
34683419 }
34693420}
34703421
@@ -3698,6 +3649,7 @@ function getPresetProperties() {
36983649}
36993650
37003651function setOpenid ( openid , isCover ) {
3652+ log ( '该方法已不建议使用,如果是 id2 用户,请使用 identify 代替,如果是 id3 用户,请使用 bindOpenid 代替' ) ;
37013653 openid = validId ( openid ) ;
37023654 if ( ! openid ) {
37033655 return false ;
@@ -3725,6 +3677,7 @@ function setOpenid(openid, isCover) {
37253677}
37263678
37273679function unsetOpenid ( val ) {
3680+ log ( '该方法已不建议使用,如果是 id3 用户,请使用 unbindOpenid 代替' ) ;
37283681 var id = validId ( val ) ;
37293682 if ( ! id ) {
37303683 return false ;
@@ -3738,10 +3691,42 @@ function unsetOpenid(val) {
37383691 var name = getOpenidNameByAppid ( ) ;
37393692 if ( hasOwnProperty$3 . call ( store . _state . identities , name ) && id === store . _state . identities [ name ] ) {
37403693 delete store . _state . identities [ name ] ;
3694+
3695+ // 2022-11-29-老乡鸡优化
3696+ var first_id = store . getFirstId ( ) ;
3697+ var distinct_id = store . getDistinctId ( ) ;
3698+ var mp_id = store . _state && store . _state . identities && store . _state . identities . $identity_mp_id ;
3699+
3700+ if ( first_id && first_id === openid && mp_id ) {
3701+ store . change ( 'first_id' , mp_id ) ;
3702+ }
3703+ if ( distinct_id && distinct_id === openid && mp_id ) {
3704+ store . change ( 'distinct_id' , mp_id ) ;
3705+ }
3706+
37413707 store . save ( ) ;
37423708 }
37433709}
37443710
3711+ function bindOpenid ( openid ) {
3712+ openid = validId ( openid ) ;
3713+ if ( ! openid ) {
3714+ return false ;
3715+ }
3716+ var name = getOpenidNameByAppid ( ) ;
3717+ this . bind ( name , openid ) ;
3718+ }
3719+
3720+ function unbindOpenid ( val ) {
3721+ var id = validId ( val ) ;
3722+ if ( ! id ) {
3723+ return false ;
3724+ }
3725+ var name = getOpenidNameByAppid ( ) ;
3726+ // 不管本地有没有都要 unbind
3727+ this . unbind ( name , val ) ;
3728+ }
3729+
37453730function setUnionid ( val ) {
37463731 var id = validId ( val ) ;
37473732 if ( id ) {
@@ -4565,8 +4550,12 @@ var functions = /*#__PURE__*/Object.freeze({
45654550 getPresetProperties : getPresetProperties ,
45664551 setOpenid : setOpenid ,
45674552 unsetOpenid : unsetOpenid ,
4553+ bindOpenid : bindOpenid ,
4554+ unbindOpenid : unbindOpenid ,
45684555 setUnionid : setUnionid ,
45694556 unsetUnionid : unsetUnionid ,
4557+ bindUnionid : setUnionid ,
4558+ unbindUnionid : unsetUnionid ,
45704559 initWithOpenid : initWithOpenid ,
45714560 bind : bind ,
45724561 unbind : unbind ,
0 commit comments