Part 1 - 鑲嵌碼
(function(i, s, o, g, r, a, m) {
// i['GoogleAnalyticsObject'] = r;
window['GoogleAnalyticsObject'] = 'ga';
// i[r] = i[r] || function() {
// (i[r].q = i[r].q || []).push(arguments)
// };
if ( ! window['ga']) {
window['ga'] = function() {
// (i[r].q = i[r].q || []).push(arguments)
if ( ! window['ga'].q) {
window['ga'].q = [];
}
window['ga'].q.push(arguments)
};
}
i['ga'].l = 1 * new Date();
// a = s.createElement(o);
a = document.createElement('script');
// m = s.getElementsByTagName(o)[0];
m = document.getElementsByTagName('script')[0];
a.async = 1;
// a.src = g;
a.src = '//www.google-analytics.com/analytics.js';
m.parentNode.insertBefore(a, m);
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
(function(i, s, o, g, r, a, m) {
// i['GoogleAnalyticsObject'] = r;
window['GoogleAnalyticsObject'] = 'ga';
// i[r] = i[r] || function() {
// (i[r].q = i[r].q || []).push(arguments)
// };
if ( ! window['ga']) {
window['ga'] = function() {
// (i[r].q = i[r].q || []).push(arguments)
if ( ! window['ga'].q) {
window['ga'].q = [];
}
window['ga'].q.push(arguments)
};
}
i['ga'].l = 1 * new Date();
// a = s.createElement(o);
a = document.createElement('script');
// m = s.getElementsByTagName(o)[0];
m = document.getElementsByTagName('script')[0];
a.async = 1;
// a.src = g;
a.src = '//www.google-analytics.com/analytics.js';
m.parentNode.insertBefore(a, m);
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
效果:
1. 建立 ga function object
2. 透過 Javascript 動態引入官方原始碼 analytics.js
0 意見:
張貼留言