Skip to content

Commit

Permalink
Merge pull request #2 from sensorsdata/v1.6
Browse files Browse the repository at this point in the history
增加app和js打通功能
  • Loading branch information
riyue authored Sep 19, 2016
2 parents 635359e + c9b5e90 commit 10204c0
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 18 deletions.
44 changes: 43 additions & 1 deletion product/sensorsdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

// 防止重复引入
sd = window[sd];
sd._t = sd._t || 1 * new Date();

if ((typeof sd !== 'function' && typeof sd !== 'object') || sd.has_load_sdk) {
return false;
Expand Down Expand Up @@ -613,7 +614,7 @@ if(typeof JSON!=='object'){JSON={}}(function(){'use strict';var rx_one=/^[\],:{}
, slice = ArrayProto.slice
, toString = ObjProto.toString
, hasOwnProperty = ObjProto.hasOwnProperty
, LIB_VERSION = '1.5.11';
, LIB_VERSION = '1.6';

sd.lib_version = LIB_VERSION;

Expand Down Expand Up @@ -2134,12 +2135,53 @@ saEvent.send = function(p, callback) {
};


function app_js_bridge(){
var app_info = null;
var todo = null;
function setAppInfo(data){
app_info = data;
if(todo){
todo(data);
}
}
//android
function getAndroid(){
if(typeof window.SensorsData_APP_JS_Bridge === 'object' && window.SensorsData_APP_JS_Bridge.sensorsdata_call_app){
app_info = SensorsData_APP_JS_Bridge.sensorsdata_call_app();
}
}
//ios
window.sensorsdata_app_js_bridge_call_js = function(data){
setAppInfo(data);
};
sd.getAppStatus = function(func){
//先获取能直接取到的安卓,ios是异步的不需要操作
getAndroid();
// 不传参数,直接返回数据
if(!func){
return app_info;
}else{
//如果传参数,保存参数。如果有数据直接执行,没数据时保存
if(app_info === null){
todo = func;
}else{
func(app_info);
}
}
};
};



sd.init = function() {

// 防止爬虫等异常情况
/*
if(!_.hasStandardBrowserEnviroment()){
return false;
}*/
app_js_bridge();

// 初始化referrer等页面属性 1.6
_.info.initPage();

Expand Down
4 changes: 2 additions & 2 deletions sensorsdata.min.js

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions src/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -1531,12 +1531,53 @@ saEvent.send = function(p, callback) {
};


function app_js_bridge(){
var app_info = null;
var todo = null;
function setAppInfo(data){
app_info = data;
if(todo){
todo(data);
}
}
//android
function getAndroid(){
if(typeof window.SensorsData_APP_JS_Bridge === 'object' && window.SensorsData_APP_JS_Bridge.sensorsdata_call_app){
app_info = SensorsData_APP_JS_Bridge.sensorsdata_call_app();
}
}
//ios
window.sensorsdata_app_js_bridge_call_js = function(data){
setAppInfo(data);
};
sd.getAppStatus = function(func){
//先获取能直接取到的安卓,ios是异步的不需要操作
getAndroid();
// 不传参数,直接返回数据
if(!func){
return app_info;
}else{
//如果传参数,保存参数。如果有数据直接执行,没数据时保存
if(app_info === null){
todo = func;
}else{
func(app_info);
}
}
};
};



sd.init = function() {

// 防止爬虫等异常情况
/*
if(!_.hasStandardBrowserEnviroment()){
return false;
}*/
app_js_bridge();

// 初始化referrer等页面属性 1.6
_.info.initPage();

Expand Down
13 changes: 7 additions & 6 deletions src/sensorsdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@

// 防止重复引入
sd = window[sd];
sd._t = sd._t || 1 * new Date();

if ((typeof sd !== 'function' && typeof sd !== 'object') || sd.has_load_sdk) {
return false;
}
sd.has_load_sdk = true;

@@include('src/json2.js')
@@include('sa-sdk-javascript/src/json2.js')

@@if (sensorsdata_mode === 'vtrack') {
@@include('src/promise.min.js')
@@include('sa-sdk-javascript/src/promise.min.js')
}

var _ = sd._ = {};

@@if (sensorsdata_mode === 'vtrack') {
@@include('src/jquery.js')
@@include('sa-sdk-javascript/src/jquery.js')
sd.$ = $;

sd.customEv = $({});
Expand Down Expand Up @@ -71,12 +72,12 @@
}

// 是否需要给可视化埋点加前缀
@@include('src/detector.min.js')
@@include('sa-sdk-javascript/src/detector.min.js')

@@include('src/sdk.js')
@@include('sa-sdk-javascript/src/sdk.js')

@@if (sensorsdata_mode === 'vtrack') {
@@include('src/vtrack.sdk.js')
@@include('sa-sdk-javascript/src/vtrack.sdk.js')
}

@@if (sensorsdata_mode !== 'vtrack') {
Expand Down
8 changes: 4 additions & 4 deletions src/vendor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
var SAS = sdkMain.SAS;

var doT = {};
@@include('src/template.js')
@@include('sa-sdk-javascript/src/template.js')
sd.template = doT.gtemplate;

//json格式化

@@include('src/jsontree.js')
@@include('sa-sdk-javascript/src/jsontree.js')
sd.JSONTree = JSONTree;


// suggest
@@include('src/suggest.js')
@@include('sa-sdk-javascript/src/suggest.js')

var Utils = {};
Utils.Formatting = {
Expand All @@ -52,7 +52,7 @@
};


@@include('src/modal.js')
@@include('sa-sdk-javascript/src/modal.js')

$.fn.gSelectBox = function() {
return $(this).each(function(a, b) {
Expand Down
10 changes: 5 additions & 5 deletions vtrack.min.js

Large diffs are not rendered by default.

0 comments on commit 10204c0

Please sign in to comment.