Bitly是用什么方法来跟踪点击的

What is the method done by Bitly to track clicks

我正在尝试实现一个代码来检测 Bitly link 并根据移动设备(Android、IOS、网站)跟踪用户,例如我想要点击 Bitly android 的用户、Apple 用户和网站用户的计数 link 所以这是我的代码

<script type="text/javascript">
    getMobileOperatingSystem();
    function getMobileOperatingSystem() {
        var userAgent = navigator.userAgent || navigator.vendor || window.opera;
        var url = "https://nch.mobi/334NXbn";
        var agnt = "web";
        var pge = "@ViewBag.campaignId";
        var link = '@Url.Action("_AddCount", "Home")';
        // Windows Phone must come first because its UA also contains "Android"
        if (/windows phone/i.test(userAgent)) {
            agnt="Windows Phone"
        }// android
        else if (/android/i.test(userAgent)) {
            url = "https://nch.mobi/3m1PM1q";
            agnt = "Android";
        }
        // iOS
        else if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
            url = "https://nch.mobi/35dOPNl";
            agnt = "IOS"
        }


        $.ajax({
            type: "POST",
            url: link,
            data: AddFormAntiForgeryToken({ 'campaign': pge, 'agent': agnt }),
            dataType: "json",
            success: function (response) {
                if (response.success) {
                    window.location.href = url;
                }
                else {
                    alert("Error occured.");
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                console.log(textStatus, errorThrown);
            }
        });
    }
    function AddFormAntiForgeryToken(data) {
        data.__RequestVerificationToken = $("input[name='__RequestVerificationToken']").val();
        return data;
    }
</script>

后端

[HttpPost]
    public ActionResult _AddCount(string campaign, string agent)
    {
        CountTableHelper hlpe = new CountTableHelper();
        var t = new CountTable
        {
            Agent = agent,
            CampaignId = Convert.ToInt32(campaign),
            CreatedDate = DateTime.UtcNow,
            IpAddress = GetIpAddress()                
        };
        hlpe.Create(t);

        return Json(new { success = true }, JsonRequestBehavior.AllowGet);
    }

但在我的例子中,Bitly 中显示的总数应该与我在数据库中收到的总数相同,但事实并非如此,虽然刷新我的页面时会跟踪新的点击,但在 Bitly 上情况并非如此,我该如何修正我的逻辑以获得相同的点击次数?

感谢您的帮助。

你的缺点是bitly用的是自己的系统。当你点击一下link。你短暂地访问了 bitly 服务器,bitly 记录了它,然后将你重定向到你想去的地方。

也有可能作为“防止滥用”(以及其他事情)的措施。刷新页面可能会触发此问题,并且不会记录另一次访问。它有很多方法可以处理这个问题,所以不知道它使用了哪一种。就跟踪 link 的方式而言,Bitly 有自己的业务需求。这些需求可能与您的不同。

Bitly 也有可能在计算总数 link 时使用最终一致性。这意味着它会记录点击但不会立即更新显示计数的页面。

虽然真正的问题可能是你为什么要数两次?为什么不使用 Bitly 的 API 直接获取计数,因为您已经为每个计数设置了单独的 link?如果您更喜欢自己的号码而不是 Bitly 的号码,那么您可能不必太担心 Bitly 的号码。

我的推荐?使用 bitly 的 API 来获取总数或使用您自己的数字。您自己的数字为您提供了更大的灵活性,因为您可以通过用户代理和 IP 地址过滤掉某些内容并过滤掉重复点击,尽管 Bitly 可能已经在一定程度上做到了这一点。