【发布时间】:2020-09-10 12:27:01
【问题描述】:
我正在尝试实现一个代码来检测 Bitly 链接并基于那里的移动设备(Android、IOS、网站)跟踪用户,例如,我想要计算点击的 android 用户、Apple 用户和网站用户的数量Bitly 链接所以这是我的代码
<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 上却是不是这样,我怎样才能修复我的逻辑以获得相同的点击次数?
感谢您的帮助。
【问题讨论】:
标签: c# jquery asp.net asp.net-mvc bitly