Google埋点实现

<!DOCTYPE html>
<html>
<head>
    <title>test</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <!-- Google tag (gtag.js) -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-DQHBQT85CC"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());

        // 设置用户ID(假设固定为A001)
        gtag('set', { 'user_id': 'A001' });

        // 配置GA属性,启用用户ID跟踪
        gtag('config', 'G-DQHBQT85CC', {
            'send_page_view': true,  // 发送页面查看事件
            'user_id': 'A001'        // 在配置中包含用户ID
        });
    </script>
</head>
<body>
    333
</body>
</html>    

 

埋点效果:

 

posted @ 2025-02-24 18:31  溜溜球_小钢wan  阅读(35)  评论(0)    收藏  举报