Skip to content

Instantly share code, notes, and snippets.

@ideacco
Created August 6, 2019 12:18
Show Gist options
  • Save ideacco/38862ee85e93870fbd606b6124305671 to your computer and use it in GitHub Desktop.
Save ideacco/38862ee85e93870fbd606b6124305671 to your computer and use it in GitHub Desktop.
获取gid
//使用官方推荐方法获取 Gid
ga(function(tracker) {
var clientId = tracker.get('clientId');
console.log('old:',clientId)
});
//使用读取cookie的方法获取gid
var Get_gid = function getCookie(c_name){
    if (document.cookie.length>0){
      var c_start = document.cookie.indexOf(c_name + "=");
      if (c_start!=-1){
        c_start=c_start + c_name.length+1
        c_end=document.cookie.indexOf(";",c_start)  
        if (c_end==-1) c_end=document.cookie.length
        return unescape(document.cookie.substring(c_start,c_end))
      }
    }
    return ""
}
var Gid = Get_gid('_ga').substring(6)
console.log('new:',Gid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment