GA埋点,统计网站流量

官方网站:https://developers.google.com/analytics/devguides/collection/gajs/


异步引用Google的Google Analytics代码

< script > (function(i, s, o, g, r, a, m) {
	i['GoogleAnalyticsObject'] = r;
	i[r] = i[r] ||
	function() { (i[r].q = i[r].q || []).push(arguments)
	},
	i[r].l = 1 * new Date();
	a = s.createElement(o),
	m = s.getElementsByTagName(o)[0];
	a.async = 1;
	a.src = g;
	m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-49980877-1', 'jenny.com');
ga('send', 'pageview'); < /script>/


调用ga()方法

<script>
require.async('zepto', function($){
	$(document).on("tap", "[data-ga-event]", function() {
        var $self, events;
        $self = $(this);
        events = $self.data("ga-event").split("/");
        if (events.length !== 3) {
            return true
        }
        events = $.map(events, function(e, i) {
            switch (e) {
                case "$text":
                    return $self.text();
                case "$href":
                    return $self.attr("href");
                default:
                    return e
            }
        });
        return ga('send', 'event', events[0], events[1], events[2]);
    });
    ga('send', 'event', '首页', '首页', '首页');
});
</script>


GA埋点:data-ga-event="jenny订单/预约页面/$text"

<a class="bottom_button submit_bottom" id="J_submit_bottom_order" data-ga-event="jenny订单/预约页面/$text">提交订单</a>



阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页