Skip to content

Commit

Permalink
feat: add f2 track.
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ committed Jun 19, 2018
1 parent 5181789 commit a301f3a
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/f2",
"version": "3.1.11",
"version": "3.1.11-beta.1",
"description": "Charts for mobile visualization.",
"keywords": [
"f2",
Expand Down
9 changes: 7 additions & 2 deletions src/core.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
const Core = {};

Core.version = '____F2_VERSION____';
Core.Global = require('./global');
const Global = require('./global');
Core.Global = Global;
Core.Chart = require('./chart/chart');
Core.Shape = require('./geom/shape/shape');
Core.G = require('./graphic/index');
Core.Util = require('./util/common');

Core.track = function(enable) {
Global.trackable = enable;
};
require('./track');

module.exports = Core;
2 changes: 2 additions & 0 deletions src/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const Util = require('./util/common');
* @class 全局配置项
*/
const Global = {
version: '3.1.11-beta.1',
trackable: true,
// 预先定义的度量
scales: {
nice: true
Expand Down
23 changes: 23 additions & 0 deletions src/track.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @fileOverview track f2
* @author sima.zhang1990@gmail.com
*/
const Global = require('./global');
const Util = require('./util/common');
const SERVER_URL = 'https://kcart.alipay.com/web/bi.do';

// 延迟发送请求
setTimeout(function() {
if (Global.trackable && Util.isBrowser) { // 只对 h5 环境下进行统计
const image = new Image();
const newObj = {
pg: document.URL,
r: new Date().getTime(),
f2: true,
version: Global.version,
page_type: 'syslog'
};
const d = encodeURIComponent(JSON.stringify([ newObj ]));
image.src = `${SERVER_URL}?BIProfile=merge&d=${d}`;
}
}, 3000);
15 changes: 15 additions & 0 deletions test/unit/core-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const expect = require('chai').expect;
const Core = require('../../src/core');

describe('Core', function() {
it('Keys', function() {
expect(Core).to.have.all.keys([ 'Global', 'Chart', 'Shape', 'G', 'Util', 'track' ]);
});

it('close track', function() {
expect(Core.Global.trackable).to.be.true; // default is open

Core.track(false);
expect(Core.Global.trackable).to.be.false;
});
});
9 changes: 9 additions & 0 deletions test/unit/global-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const expect = require('chai').expect;
const Global = require('../../src/global');
const pkg = require('../../package.json');

describe('Global', () => {
it('version sync', () => {
expect(Global.version).equal(pkg.version);
});
});
11 changes: 0 additions & 11 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const webpack = require('webpack');
const resolve = require('path').resolve;
const pkg = require('./package.json');

module.exports = {
entry: {
Expand All @@ -25,16 +24,6 @@ module.exports = {
babelrc: true
}
}
},
{
test: /core\.js$/,
use: {
loader: 'string-replace-loader',
options: {
search: '____F2_VERSION____',
replace: pkg.version
}
}
}
]
},
Expand Down

0 comments on commit a301f3a

Please sign in to comment.