|
2081 | 2081 | }; |
2082 | 2082 |
|
2083 | 2083 | var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term'; |
2084 | | - var sdkversion_placeholder = '1.21.4'; |
| 2084 | + var sdkversion_placeholder = '1.21.5'; |
2085 | 2085 |
|
2086 | 2086 | function parseSuperProperties(data) { |
2087 | 2087 | var obj = data.properties; |
|
2238 | 2238 | props.$url = getURL(); |
2239 | 2239 | props.$url_path = location.pathname; |
2240 | 2240 | props.$title = document.title; |
2241 | | - props.$viewport_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || 0; |
2242 | 2241 |
|
2243 | 2242 | return props; |
2244 | 2243 | } |
|
2521 | 2520 | }; |
2522 | 2521 | }, |
2523 | 2522 | properties: function() { |
2524 | | - return { |
| 2523 | + var viewportHeightValue = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0; |
| 2524 | + var viewportWidthValue = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || 0; |
| 2525 | + var propertiesObj = { |
2525 | 2526 | $timezone_offset: new Date().getTimezoneOffset(), |
2526 | 2527 | $screen_height: Number(screen.height) || 0, |
2527 | 2528 | $screen_width: Number(screen.width) || 0, |
| 2529 | + $viewport_height: viewportHeightValue, |
| 2530 | + $viewport_width: viewportWidthValue, |
2528 | 2531 | $lib: 'js', |
2529 | 2532 | $lib_version: sdkversion_placeholder |
2530 | 2533 | }; |
| 2534 | + return propertiesObj; |
2531 | 2535 | }, |
2532 | 2536 | currentProps: {}, |
2533 | 2537 | register: function(obj) { |
|
2958 | 2962 | addEvent(window, hashEvent, callback); |
2959 | 2963 | } |
2960 | 2964 |
|
2961 | | - function addSinglePageEvent(callback) { |
2962 | | - var current_url = location.href; |
2963 | | - var historyPushState = window.history.pushState; |
2964 | | - var historyReplaceState = window.history.replaceState; |
2965 | | - |
2966 | | - if (isFunction(window.history.pushState)) { |
2967 | | - window.history.pushState = function() { |
2968 | | - historyPushState.apply(window.history, arguments); |
2969 | | - callback(current_url); |
2970 | | - current_url = location.href; |
2971 | | - }; |
2972 | | - } |
| 2965 | + var singlePage = { |
| 2966 | + is_create: false, |
| 2967 | + current_url: location.href, |
| 2968 | + eventList: [], |
| 2969 | + create: function() { |
| 2970 | + var _this = this; |
2973 | 2971 |
|
2974 | | - if (isFunction(window.history.replaceState)) { |
2975 | | - window.history.replaceState = function() { |
2976 | | - historyReplaceState.apply(window.history, arguments); |
2977 | | - callback(current_url); |
2978 | | - current_url = location.href; |
2979 | | - }; |
2980 | | - } |
| 2972 | + function publish() { |
| 2973 | + each(_this.eventList, function(event) { |
| 2974 | + if (isFunction(event)) { |
| 2975 | + event(_this.current_url); |
| 2976 | + } |
| 2977 | + }); |
| 2978 | + _this.current_url = location.href; |
| 2979 | + } |
| 2980 | + var historyPushState = window.history.pushState; |
| 2981 | + var historyReplaceState = window.history.replaceState; |
2981 | 2982 |
|
2982 | | - var singlePageEvent; |
2983 | | - if (window.document.documentMode) { |
2984 | | - singlePageEvent = 'hashchange'; |
2985 | | - } else { |
2986 | | - singlePageEvent = historyPushState ? 'popstate' : 'hashchange'; |
2987 | | - } |
| 2983 | + if (isFunction(window.history.pushState)) { |
| 2984 | + window.history.pushState = function() { |
| 2985 | + historyPushState.apply(window.history, arguments); |
| 2986 | + publish(); |
| 2987 | + }; |
| 2988 | + } |
2988 | 2989 |
|
2989 | | - addEvent(window, singlePageEvent, function() { |
2990 | | - callback(current_url); |
2991 | | - current_url = location.href; |
2992 | | - }); |
| 2990 | + if (isFunction(window.history.replaceState)) { |
| 2991 | + window.history.replaceState = function() { |
| 2992 | + historyReplaceState.apply(window.history, arguments); |
| 2993 | + publish(); |
| 2994 | + }; |
| 2995 | + } |
2993 | 2996 |
|
| 2997 | + var singlePageEvent; |
| 2998 | + if (window.document.documentMode) { |
| 2999 | + singlePageEvent = 'hashchange'; |
| 3000 | + } else { |
| 3001 | + singlePageEvent = historyPushState ? 'popstate' : 'hashchange'; |
| 3002 | + } |
2994 | 3003 |
|
| 3004 | + addEvent(window, singlePageEvent, function() { |
| 3005 | + publish(); |
| 3006 | + }); |
| 3007 | + this.is_create = true; |
| 3008 | + }, |
| 3009 | + subscribe: function(callback) { |
| 3010 | + if (!this.is_create) { |
| 3011 | + this.create(); |
| 3012 | + } |
| 3013 | + if (isFunction(callback)) { |
| 3014 | + this.eventList.push(callback); |
| 3015 | + } |
| 3016 | + }, |
| 3017 | + prepend: function(callback) { |
| 3018 | + if (!this.is_create) { |
| 3019 | + this.create(); |
| 3020 | + } |
| 3021 | + if (isFunction(callback)) { |
| 3022 | + this.eventList.unshift(callback); |
| 3023 | + } |
| 3024 | + } |
| 3025 | + }; |
| 3026 | + |
| 3027 | + function addSinglePageEvent(callback) { |
| 3028 | + singlePage.subscribe(callback); |
2995 | 3029 | } |
2996 | 3030 |
|
2997 | 3031 | function listenPageState(obj) { |
|
3457 | 3491 | addSinglePageEvent: addSinglePageEvent, |
3458 | 3492 | listenPageState: listenPageState, |
3459 | 3493 | bindReady: bindReady, |
| 3494 | + singlePage: singlePage, |
3460 | 3495 | xhr: xhr, |
3461 | 3496 | ajax: ajax, |
3462 | 3497 | jsonp: jsonp, |
|
4630 | 4665 | } |
4631 | 4666 | return prop; |
4632 | 4667 | }, |
| 4668 | + addPointerEventProp: function(ev, target) { |
| 4669 | + function getScroll() { |
| 4670 | + var scrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft || 0; |
| 4671 | + var scrollTop = document.body.scrollTop || document.documentElement.scrollTop || 0; |
| 4672 | + return { |
| 4673 | + scrollLeft: scrollLeft, |
| 4674 | + scrollTop: scrollTop |
| 4675 | + }; |
| 4676 | + } |
| 4677 | + |
| 4678 | + function getElementPosition(target) { |
| 4679 | + if (document.documentElement.getBoundingClientRect) { |
| 4680 | + var targetEle = target.getBoundingClientRect(); |
| 4681 | + return { |
| 4682 | + targetEleX: targetEle.left + getScroll().scrollLeft || 0, |
| 4683 | + targetEleY: targetEle.top + getScroll().scrollTop || 0 |
| 4684 | + }; |
| 4685 | + } |
| 4686 | + } |
| 4687 | + |
| 4688 | + function toFixedThree(val) { |
| 4689 | + return Number(Number(val).toFixed(3)); |
| 4690 | + } |
| 4691 | + |
| 4692 | + function getPage(ev) { |
| 4693 | + var pageX = ev.pageX || ev.clientX + getScroll().scrollLeft || ev.offsetX + getElementPosition(target).targetEleX || 0; |
| 4694 | + var pageY = ev.pageY || ev.clientY + getScroll().scrollTop || ev.offsetY + getElementPosition(target).targetEleY || 0; |
| 4695 | + return { |
| 4696 | + $page_x: toFixedThree(pageX), |
| 4697 | + $page_y: toFixedThree(pageY) |
| 4698 | + }; |
| 4699 | + } |
| 4700 | + return getPage(ev); |
| 4701 | + }, |
4633 | 4702 | start: function(ev, target, tagName, customProps, callback) { |
4634 | 4703 | var userCustomProps = isObject(customProps) ? customProps : {}; |
4635 | 4704 | var userCallback = isFunction(callback) ? callback : isFunction(customProps) ? customProps : undefined; |
|
4645 | 4714 | prop = extend(prop, customP); |
4646 | 4715 | } |
4647 | 4716 | } |
4648 | | - prop = extend(prop, userCustomProps); |
| 4717 | + prop = extend(prop, this.addPointerEventProp(ev, target), userCustomProps); |
4649 | 4718 | if (tagName === 'a' && sd.para.heatmap && sd.para.heatmap.isTrackLink === true) { |
4650 | 4719 | sd.trackLink({ |
4651 | 4720 | event: ev, |
|
4758 | 4827 | if (!this.inter) { |
4759 | 4828 | para.$viewport_position = (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || document.body.scrollTop || 0; |
4760 | 4829 | para.$viewport_position = Math.round(para.$viewport_position) || 0; |
4761 | | - para.$viewport_height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0; |
4762 | | - para.$viewport_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || 0; |
4763 | 4830 | if (isNoDelay) { |
4764 | 4831 | interDelay.main(para, true); |
4765 | 4832 | } else { |
|
5853 | 5920 | distinct_id: id |
5854 | 5921 | }) && id !== sd.store.getDistinctId()) { |
5855 | 5922 | if (isObject(sd.store._state.identities) && sd.store._state.identities.hasOwnProperty(sd.para.login_id_key) && id === sd.store._state.first_id) { |
5856 | | - callback && callback(); |
| 5923 | + isFunction(callback) && callback(); |
5857 | 5924 | return false; |
5858 | 5925 | } |
5859 | 5926 |
|
|
5877 | 5944 | }); |
5878 | 5945 | } |
5879 | 5946 | } else { |
5880 | | - callback && callback(); |
| 5947 | + isFunction(callback) && callback(); |
5881 | 5948 | } |
5882 | | - callback && callback(); |
5883 | 5949 | } |
5884 | 5950 |
|
5885 | 5951 | function logout(isChangeId) { |
|
7844 | 7910 | source: 'sa-web-sdk', |
7845 | 7911 | type: 'v-is-vtrack', |
7846 | 7912 | data: { |
7847 | | - sdkversion: '1.21.4' |
| 7913 | + sdkversion: '1.21.5' |
7848 | 7914 | } |
7849 | 7915 | }, |
7850 | 7916 | '*' |
|
0 commit comments