Skip to content

Commit

Permalink
add analytics codes (cocos2d#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
minggo authored Dec 12, 2017
1 parent f87827f commit 99fc506
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const {WorkerBase, registerWorker} = require('./WorkerBase');

class BuildWorker extends WorkerBase {
run(state, callback) {
Utils.recordBuild();

Editor.Ipc.sendToAll('creator-luacpp-support:state-changed', 'start', 0);
Utils.log('[creator-luacpp-support] build start');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Constants.READER_PATH = Path.join(Constants.PACKAGE_PATH, 'reader');
// the folder that all resources are copied to
Constants.RESOURCE_FOLDER_NAME = 'creator';

Constants.VERDION = '0.4.0';

Constants.PROFILE_DEFAULTS = {
setup: false,
path: '',
Expand Down
43 changes: 43 additions & 0 deletions creator_project/packages/creator-luacpp-support/core/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const Path = require('path');
const Fs = require('fire-fs');
const Constants = require('./Constants');

let analytics = undefined;

class Utils {
static log(data) {
const logFunc = Editor ? Editor.log : console.log;
Expand Down Expand Up @@ -94,6 +96,47 @@ class Utils {
static replaceExt(path, ext) {
return (path.substr(0, path.lastIndexOf(".")) + ext);
}

static recordBuild() {
Utils.initAnalytics(function(analytics){
analytics.CAEvent.onEvent({ eventName: 'build' });
});
}

static initAnalytics(callback) {
if (Utils._isAnalyticsInitialized()) {
callback(analytics);
return;
}

var src = "https://analytics.cocos.com/assets/js/cocosAnalytics.min.js";
var script = document.createElement('script');
script.onload = function () {
document.head.removeChild(script);

analytics = cocosAnalytics;
if (typeof(analytics) !== 'undefined') {
analytics.init({
appID: '630639001',
appSecret: 'a2d8adf595006f7a6af5f9b7e66a31d7',
channel: 'creator',
version: Constants.VERDION
});
analytics.CAAccount.loginStart();

callback(analytics);
}
};
script.onerror = function () {
document.head.removeChild(script);
};
script.src = src;
document.head.appendChild(script);
}

static _isAnalyticsInitialized() {
return typeof(analytics) !== 'undefined';
}
}

module.exports = Utils;
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FireParser {
constructor() {
this._state = state;
this._json_file = null;
this._json_output = {version: '0.3', root: {}};
this._json_output = {version: Constants.VERDION, root: {}};
this._creatorassets = null;
}

Expand Down

0 comments on commit 99fc506

Please sign in to comment.