diff --git a/creator_project/packages/creator-luacpp-support/core/BuildWorker.js b/creator_project/packages/creator-luacpp-support/core/BuildWorker.js index 2338fcc5..b5b75b77 100644 --- a/creator_project/packages/creator-luacpp-support/core/BuildWorker.js +++ b/creator_project/packages/creator-luacpp-support/core/BuildWorker.js @@ -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'); diff --git a/creator_project/packages/creator-luacpp-support/core/Constants.js b/creator_project/packages/creator-luacpp-support/core/Constants.js index 0800184b..dc7efc87 100644 --- a/creator_project/packages/creator-luacpp-support/core/Constants.js +++ b/creator_project/packages/creator-luacpp-support/core/Constants.js @@ -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: '', diff --git a/creator_project/packages/creator-luacpp-support/core/Utils.js b/creator_project/packages/creator-luacpp-support/core/Utils.js index 75b51f75..a2c25209 100644 --- a/creator_project/packages/creator-luacpp-support/core/Utils.js +++ b/creator_project/packages/creator-luacpp-support/core/Utils.js @@ -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; @@ -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; diff --git a/creator_project/packages/creator-luacpp-support/core/parser/ConvertFireToJson.js b/creator_project/packages/creator-luacpp-support/core/parser/ConvertFireToJson.js index 19f0b099..9ee63007 100644 --- a/creator_project/packages/creator-luacpp-support/core/parser/ConvertFireToJson.js +++ b/creator_project/packages/creator-luacpp-support/core/parser/ConvertFireToJson.js @@ -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; }