@@ -34,7 +34,8 @@ sa.para = {
3434 } ,
3535 preset_events : {
3636 moments_page : false ,
37- defer_track : false
37+ defer_track : false ,
38+ share_info_use_string : false
3839 } ,
3940 batch_send : true ,
4041 storage_store_key : 'sensorsdata2015_wechat' ,
@@ -158,12 +159,13 @@ var ArrayProto = Array.prototype,
158159 slice = ArrayProto . slice ,
159160 toString = ObjProto . toString ,
160161 hasOwnProperty = ObjProto . hasOwnProperty ,
161- LIB_VERSION = '1.14.18 ' ,
162+ LIB_VERSION = '1.14.19 ' ,
162163 LIB_NAME = 'MiniProgram' ;
163164
164165var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term' ;
165166var latest_source_channel = [ '$latest_utm_source' , '$latest_utm_medium' , '$latest_utm_campaign' , '$latest_utm_content' , '$latest_utm_term' , '$latest_sa_utm' ] ;
166167var latest_share_info = [ '$latest_share_distinct_id' , '$latest_share_url_path' , '$latest_share_depth' , '$latest_share_method' ] ;
168+ var share_info_key = [ 'sensors_share_d' , 'sensors_share_p' , 'sensors_share_i' , 'sensors_share_m' ] ;
167169
168170var mpshow_time = null ;
169171
@@ -861,25 +863,94 @@ _.getMPScene = function(scene_value) {
861863 }
862864} ;
863865
866+ _ . objToParam = function ( param , isEncode ) {
867+ if ( Object . prototype . toString . call ( param ) !== '[object Object]' ) {
868+ logger . info ( '请传入有效对象' ) ;
869+ return '' ;
870+ } ;
871+ var queryParam = [ ] ;
872+ for ( var key in param ) {
873+ if ( param . hasOwnProperty ( key ) ) {
874+ var value = param [ key ] ;
875+ if ( typeof value == 'undefined' ) {
876+ queryParam . push ( key + '=' ) ;
877+ } else {
878+ value = isEncode ? encodeURIComponent ( value ) : value ;
879+ queryParam . push ( key + '=' + value ) ;
880+ }
881+ }
882+ } ;
883+ return queryParam . join ( '&' ) ;
884+ } ;
885+
886+ _ . delObjectKey = function ( obj ) {
887+ if ( Object . prototype . toString . call ( obj ) !== '[object Object]' ) {
888+ logger . info ( '请传入有效对象' ) ;
889+ return ;
890+ } ;
891+ for ( let i = 0 ; i < share_info_key . length ; i ++ ) {
892+ delete obj [ share_info_key [ i ] ]
893+ }
894+ } ;
895+
896+ _ . shareInfoData = function ( para ) {
897+ var shareData = { } ;
898+ var share = { } ;
899+ if ( ! sa . para . preset_events . share_info_use_string ) {
900+ if ( para . query . sampshare ) {
901+ share = _ . decodeURIComponent ( para . query . sampshare ) ;
902+ if ( _ . isJSONString ( share ) ) {
903+ share = JSON . parse ( share ) ;
904+ } else {
905+ return { } ;
906+ }
907+ } else {
908+ return { } ;
909+ } ;
910+
911+ shareData = {
912+ depth : share . d ,
913+ path : share . p ,
914+ id : share . i ,
915+ method : share . m
916+ } ;
917+ } else {
918+ share = para . query ;
919+ for ( var i = 0 ; i < share_info_key . length ; i ++ ) {
920+ if ( ! share . hasOwnProperty ( share_info_key [ i ] ) ) {
921+ return { } ;
922+ }
923+ share [ share_info_key [ i ] ] = _ . decodeURIComponent ( share [ share_info_key [ i ] ] )
924+ } ;
925+
926+ shareData = {
927+ depth : Number ( share . sensors_share_d ) ,
928+ path : share . sensors_share_p || '' ,
929+ id : share . sensors_share_i || '' ,
930+ method : share . sensors_share_m || ''
931+ } ;
932+ } ;
933+
934+ return shareData ;
935+ }
936+
864937_ . setShareInfo = function ( para , prop ) {
865938 var share = { } ;
866939 var obj = { } ;
867940 var current_id = sa . store . getDistinctId ( ) ;
868941 var current_first_id = sa . store . getFirstId ( ) ;
869- if ( para && _ . isObject ( para . query ) && para . query . sampshare ) {
870- share = _ . decodeURIComponent ( para . query . sampshare ) ;
871- if ( _ . isJSONString ( share ) ) {
872- share = JSON . parse ( share ) ;
942+ if ( para && _ . isObject ( para . query ) ) {
943+ share = _ . shareInfoData ( para ) ;
944+ if ( ! _ . isEmptyObject ( share ) ) {
945+ var depth = share . depth ,
946+ path = share . path ,
947+ id = share . id ,
948+ method = share . method ;
873949 } else {
874- return { } ;
950+ return { }
875951 }
876- } else {
877- return { } ;
878- }
879- var depth = share . d ;
880- var path = share . p ;
881- var id = share . i ;
882- var method = share . m ;
952+ } ;
953+
883954 if ( typeof id === 'string' ) {
884955 prop . $share_distinct_id = id ;
885956 share_distinct_id = id ;
@@ -919,12 +990,25 @@ _.setShareInfo = function(para, prop) {
919990} ;
920991
921992_ . getShareInfo = function ( ) {
922- return JSON . stringify ( {
993+ if ( sa . para . preset_events . share_info_use_string ) {
994+ var param = {
995+ sensors_share_i : sa . store . getDistinctId ( ) || '取值异常' ,
996+ sensors_share_p : _ . getCurrentPath ( ) ,
997+ sensors_share_d : query_share_depth ,
998+ sensors_share_m : share_method
999+ } ;
1000+
1001+ return _ . objToParam ( param , true ) ;
1002+ } ;
1003+
1004+ var share_info = JSON . stringify ( {
9231005 i : sa . store . getDistinctId ( ) || '取值异常' ,
9241006 p : _ . getCurrentPath ( ) ,
9251007 d : query_share_depth ,
9261008 m : share_method
9271009 } ) ;
1010+
1011+ return 'sampshare=' + encodeURIComponent ( share_info )
9281012} ;
9291013
9301014_ . detectOptionQuery = function ( para ) {
@@ -1376,7 +1460,6 @@ sa.prepareData = function(p, callback) {
13761460 if ( ! p . type || p . type . slice ( 0 , 7 ) !== 'profile' ) {
13771461 data . _track_id = Number ( String ( Math . random ( ) ) . slice ( 2 , 5 ) + String ( Math . random ( ) ) . slice ( 2 , 4 ) + String ( Date . now ( ) ) . slice ( - 4 ) ) ;
13781462 data . properties = _ . extend ( { } , _ . info . properties , sa . store . getProps ( ) , _ . info . currentProps , data . properties ) ;
1379-
13801463 data . properties . $is_first_day = _ . getIsFirstDay ( ) ;
13811464
13821465 var refPage = _ . getRefPage ( ) ;
@@ -2218,8 +2301,11 @@ sa.autoTrackCustom = {
22182301 } else {
22192302 prop . $scene = '未取到值' ;
22202303 }
2221- if ( para && para . scene && para . scene === 1010 && para . query && para . query . sampshare ) {
2222- delete para . query . sampshare
2304+ if ( para && para . scene && para . scene === 1010 && para . query ) {
2305+ if ( para . query . sampshare ) {
2306+ delete para . query . sampshare
2307+ }
2308+ _ . delObjectKey ( para . query ) ;
22232309 }
22242310 if ( para && para . path ) {
22252311 prop . $url_path = _ . getPath ( para . path ) ;
@@ -2267,8 +2353,11 @@ sa.autoTrackCustom = {
22672353 prop . $scene = '未取到值' ;
22682354 }
22692355
2270- if ( para && para . scene && para . scene === 1010 && para . query && para . query . sampshare ) {
2271- delete para . query . sampshare
2356+ if ( para && para . scene && para . scene === 1010 && para . query ) {
2357+ if ( para . query . sampshare ) {
2358+ delete para . query . sampshare
2359+ } ;
2360+ _ . delObjectKey ( para . query )
22722361 }
22732362
22742363 if ( para && para . path ) {
@@ -2351,8 +2440,11 @@ sa.appLaunch = function(option, prop) {
23512440 } else {
23522441 obj . $scene = '未取到值' ;
23532442 }
2354- if ( option && option . scene && option . scene === 1010 && option . query && option . query . sampshare ) {
2355- delete option . query . sampshare
2443+ if ( option && option . scene && option . scene === 1010 && option . query ) {
2444+ if ( option . query . sampshare ) {
2445+ delete option . query . sampshare
2446+ } ;
2447+ _ . delObjectKey ( option . query ) ;
23562448 }
23572449 if ( option && option . path ) {
23582450 obj . $url_path = _ . getPath ( option . path ) ;
@@ -2396,8 +2488,11 @@ sa.appShow = function(option, prop) {
23962488 } else {
23972489 obj . $scene = '未取到值' ;
23982490 }
2399- if ( option && option . scene && option . scene === 1010 && option . query && option . query . sampshare ) {
2400- delete option . query . sampshare
2491+ if ( option && option . scene && option . scene === 1010 && option . query ) {
2492+ if ( option . query . sampshare ) {
2493+ delete option . query . sampshare
2494+ } ;
2495+ _ . delObjectKey ( option . query ) ;
24012496 }
24022497
24032498 if ( option && option . path ) {
0 commit comments