Skip to content

Commit

Permalink
feat: 埋点统计
Browse files Browse the repository at this point in the history
  • Loading branch information
ICELI committed Jun 20, 2017
1 parent 7998c98 commit 5b6a806
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/page/home/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="text-info">
<h1>Hello, Angular!</h1>
<p>Welcome to your Angular.js app!</p>
<p><a class="btn btn-primary btn-lg" href="https://github.com/jm-team/ng-seed" target="_blank"
<p tj-page><a class="btn btn-primary btn-lg" href="https://github.com/jm-team/ng-seed" target="_blank"
role="button">Learn more</a></p>

<!-- JiaThis Button BEGIN -->
Expand Down Expand Up @@ -40,4 +40,4 @@ <h1>Hello, Angular!</h1>
</div>
<!-- 聚贸服务侧边栏-->
<div jm-toolbar toggle-class="on" visibility-height="100"></div>
</div>
</div>
1 change: 1 addition & 0 deletions src/service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ require('./util.js');
require('./store.js');
require('./api.js');
require('./httpInterceptor.js');
require('./tj.js');
84 changes: 84 additions & 0 deletions src/service/tj.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
var app = require('app');
// TJ大神,佑我无BUG
app.factory('TJ', function($location, $rootScope, $resource) {
return {
formUrl: document.referrer, // $locationChangeStart
init: function(option) {
var self = this;

option = angular.extend({
url: $location.absUrl(),
}, option);

this.pageInit().get(option, function(data) {
console.log(data, 'success');
}, function(data) {
console.log(data, 'error');
});

this.formUrl = option.url;

$rootScope.$on('$locationChangeStart', function() {
// 统计流向
self.save({ from: self.formUrl, target: $location.absUrl() });
});
},
save: function(option, isTJPage) {
var formUrl = this.formUrl;

option = angular.extend({
from: formUrl,
//target: '',
}, option);

// 初始化或刷新页面都不需要统计为跳转事件
if (!option.from || option.from === option.target) {
return false;
}

this.openPage().get(option, function(data) {
console.log(data, 'success');
}, function(data) {
console.log(data, 'error');
});

this.formUrl = isTJPage ? option.from : option.target;
},
// api pageInit
pageInit: function() {
return $resource('/bi/pageInit');
},
// api openPage
openPage: function() {
return $resource('/bi/openPage');
},
};
});

// 指定需要统计的链接 <element><a></a></element>
app.directive('tjPage', function() {
return {
restrict: 'AE',
controller: function() {
this.isTJPage = true;
}
};
}).directive('a', function(TJ) {
return {
restrict: 'AE',
require: '^?tjPage',
replace: true,
link: function(scope, element, attrs, tjPageController) {
tjPageController && tjPageController.isTJPage &&
element.on('click', function(e) {
// 统计流向
TJ.save({ from: TJ.formUrl, target: e.target.getAttribute('href') }, true);
});
},
};
});

app.run(function(TJ) {
// 统计初始化页面
TJ.init();
});

0 comments on commit 5b6a806

Please sign in to comment.