Skip to content

Commit

Permalink
📦 - Build 0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
limichange committed Feb 17, 2017
1 parent 368c23b commit 90c8793
Show file tree
Hide file tree
Showing 4 changed files with 289 additions and 0 deletions.
144 changes: 144 additions & 0 deletions dist/yuki-gta.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
'use strict';

var Common = {
removeElement: function removeElement (el) {
el.parentNode.removeChild(el);
}
};

var Base = function Base () {
this.name = 'base';
};

Base.prototype.createScript = function createScript (src) {
var script = document.createElement('script');
script.async = 1;
script.src = src;
return script
};

Base.prototype.loadScript = function loadScript (script, key, removeAfterLoad) {
if ( removeAfterLoad === void 0 ) removeAfterLoad = false;

script.onerror = function () {
window[key] = null;
Common.removeElement(script);
};

script.onload = function () {
removeAfterLoad && Common.removeElement(script);
};

var firstScript = document.getElementsByTagName('script')[0];
firstScript.parentNode.insertBefore(script, firstScript);
};

var Baidu = (function (Base$$1) {
function Baidu (account) {
Base$$1.call(this);
window._hmt = window._hmt || [];
var script = this.createScript(("//hm.baidu.com/hm.js?" + account));
this.loadScript(script, '_hmt');
}

if ( Base$$1 ) Baidu.__proto__ = Base$$1;
Baidu.prototype = Object.create( Base$$1 && Base$$1.prototype );
Baidu.prototype.constructor = Baidu;

Baidu.prototype.pageview = function pageview (page) {
console.log(page);
window._hmt && window._hmt.push(['_trackPageview', page]);
};

Baidu.prototype.event = function event (options) {
console.log(options);
window._hmt && window._hmt.push([
'_trackEvent',
options.page,
options.action,
options.label,
options.value
]);
};

return Baidu;
}(Base));

var Google = (function (Base$$1) {
function Google (account) {
Base$$1.call(this);
window.GoogleAnalyticsObject = 'ga';

var ga = window.ga || function () {
ga.q.push(arguments);
};

ga.q = [];
ga.l = 1 * new Date();

var script = this.createScript('//www.google-analytics.com/analytics.js');
this.loadScript(script, 'ga');

ga('create', account, 'auto', 'moment');
ga('send', 'pageview');

window.ga = ga;
}

if ( Base$$1 ) Google.__proto__ = Base$$1;
Google.prototype = Object.create( Base$$1 && Base$$1.prototype );
Google.prototype.constructor = Google;

Google.prototype.pageview = function pageview (page) {
console.log(page);
window.ga('send', 'pageview', page);
};

Google.prototype.event = function event (options) {
console.log(options);
window.ga(
'send',
'event',
options.page,
options.action,
options.label,
options.value
);
};

return Google;
}(Base));

var Providers = {
baidu: Baidu,
google: Google
};

var yukiGta = function yukiGta (options) {
var this$1 = this;
if ( options === void 0 ) options = {};

this.version = '0.0.1';

this.providers = Object.keys(options).map(function (key) {
return this$1.registerProvider(options[key], Providers[key])
});
};

yukiGta.prototype.registerProvider = function registerProvider (option, Provider) {
return new Provider(option)
};

yukiGta.prototype.pageview = function pageview (page) {
this.providers.forEach(function (p) {
p.pageview(page);
});
};

yukiGta.prototype.event = function event (options) {
this.providers.forEach(function (p) {
p.event(options);
});
};

module.exports = yukiGta;
142 changes: 142 additions & 0 deletions dist/yuki-gta.es5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
var Common = {
removeElement: function removeElement (el) {
el.parentNode.removeChild(el);
}
};

var Base = function Base () {
this.name = 'base';
};

Base.prototype.createScript = function createScript (src) {
var script = document.createElement('script');
script.async = 1;
script.src = src;
return script
};

Base.prototype.loadScript = function loadScript (script, key, removeAfterLoad) {
if ( removeAfterLoad === void 0 ) removeAfterLoad = false;

script.onerror = function () {
window[key] = null;
Common.removeElement(script);
};

script.onload = function () {
removeAfterLoad && Common.removeElement(script);
};

var firstScript = document.getElementsByTagName('script')[0];
firstScript.parentNode.insertBefore(script, firstScript);
};

var Baidu = (function (Base$$1) {
function Baidu (account) {
Base$$1.call(this);
window._hmt = window._hmt || [];
var script = this.createScript(("//hm.baidu.com/hm.js?" + account));
this.loadScript(script, '_hmt');
}

if ( Base$$1 ) Baidu.__proto__ = Base$$1;
Baidu.prototype = Object.create( Base$$1 && Base$$1.prototype );
Baidu.prototype.constructor = Baidu;

Baidu.prototype.pageview = function pageview (page) {
console.log(page);
window._hmt && window._hmt.push(['_trackPageview', page]);
};

Baidu.prototype.event = function event (options) {
console.log(options);
window._hmt && window._hmt.push([
'_trackEvent',
options.page,
options.action,
options.label,
options.value
]);
};

return Baidu;
}(Base));

var Google = (function (Base$$1) {
function Google (account) {
Base$$1.call(this);
window.GoogleAnalyticsObject = 'ga';

var ga = window.ga || function () {
ga.q.push(arguments);
};

ga.q = [];
ga.l = 1 * new Date();

var script = this.createScript('//www.google-analytics.com/analytics.js');
this.loadScript(script, 'ga');

ga('create', account, 'auto', 'moment');
ga('send', 'pageview');

window.ga = ga;
}

if ( Base$$1 ) Google.__proto__ = Base$$1;
Google.prototype = Object.create( Base$$1 && Base$$1.prototype );
Google.prototype.constructor = Google;

Google.prototype.pageview = function pageview (page) {
console.log(page);
window.ga('send', 'pageview', page);
};

Google.prototype.event = function event (options) {
console.log(options);
window.ga(
'send',
'event',
options.page,
options.action,
options.label,
options.value
);
};

return Google;
}(Base));

var Providers = {
baidu: Baidu,
google: Google
};

var yukiGta = function yukiGta (options) {
var this$1 = this;
if ( options === void 0 ) options = {};

this.version = '0.0.1';

this.providers = Object.keys(options).map(function (key) {
return this$1.registerProvider(options[key], Providers[key])
});
};

yukiGta.prototype.registerProvider = function registerProvider (option, Provider) {
return new Provider(option)
};

yukiGta.prototype.pageview = function pageview (page) {
this.providers.forEach(function (p) {
p.pageview(page);
});
};

yukiGta.prototype.event = function event (options) {
this.providers.forEach(function (p) {
p.event(options);
});
};

export default yukiGta;
2 changes: 2 additions & 0 deletions dist/yuki-gta.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Base.prototype.loadScript = function loadScript (script, key, removeAfterLoad) {

var Baidu = (function (Base$$1) {
function Baidu (account) {
Base$$1.call(this);
window._hmt = window._hmt || [];
var script = this.createScript(("//hm.baidu.com/hm.js?" + account));
this.loadScript(script, '_hmt');
Expand Down Expand Up @@ -69,6 +70,7 @@ var Baidu = (function (Base$$1) {

var Google = (function (Base$$1) {
function Google (account) {
Base$$1.call(this);
window.GoogleAnalyticsObject = 'ga';

var ga = window.ga || function () {
Expand Down
1 change: 1 addition & 0 deletions dist/yuki-gta.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 90c8793

Please sign in to comment.