ga or _gaq.push for Google Analytics event tracking?

前端 未结 5 1344
有刺的猬
有刺的猬 2020-12-02 07:37

I would like to track an onclick of a button on a page on a site, after a condition is passed checking if a cookie is present.

Very simple but which syn

5条回答
  •  孤城傲影
    2020-12-02 08:37

    I would create a function if you need to track different events, that way your code will be cleaner.

    analytics.js

    ga.js

    function TrackEventGA(Category, Action, Label, Value) {
        "use strict";
        if (typeof (_gaq) !== "undefined") {
            _gaq.push(['_trackEvent', Category, Action, Label, Value]);
        } else if (typeof (ga) !== "undefined") {
            ga('send', 'event', Category, Action, Label, Value);
        }
    }
    TrackEventGA('QR_Win_A_Grand', 'Clicked_through_to_register');
    

提交回复
热议问题