我如何限制广告商的次数'的广告在某一天用Javascript显示
How can I cap the number of times an advertiser's ad is shown in a given day in Javascript?
以下是场景:
在我们的网站上,我们有3个广告商。广告商让我们为他们的产品收集电子邮件。
每个广告商每天收集的电子邮件数量上限为500封。一旦我们在一天内收到500封电子邮件,我们就需要停止显示广告商提供的内容。
为了构建广告商堆栈,我们有一个Javascript数组,用于确定为给定用户显示哪些广告商。我们把每个广告商都推到阵列中。如果我们没有广告商,我们会将用户重定向到另一个页面。
基本上,我需要做的是构建一个计数为"500"的迭代,如果我们在给定的一天内收到500封电子邮件,我们就不会向广告商显示。
// what offers will be show
var offer_order = [];
// what needs to be written is an iteration that counts up to '500',
// then if its in a given day, do not show the respective offer
// add the advertisers to the order being shown
// if ( cap <= '500' ) {
offer_order.push('advertiser-1');
// }
// if ( cap <= '300' ) {
offer_order.push('advertiser-2');
// }
// this offer has no cap, so it will always be shown
offer_order.push('advertiser-3');
// I removed all of the functionality that sets the starting offer
// and controls showing the next offer, so don't worry about this not working
// send lead data on submit
$('.submit').on('click', function() {
$.ajax({
url: 'http://domain.com/send-data.php',
data: $('#user_data').serialize(),
type: 'POST',
}).done(function(responseData) {
// in our response data, we either get back 'success' or 'fail'
// we need to build our iteration here
// if the beginning offer is equal to whats next, then were done, so lets move to the next page
if ( next == $(starting_offer).data("start") ) {
window.location.href = "<?php echo $next_page; ?>";
}
}).fail(function() {
// if the beginning offer is equal to whats next, then were done, so lets move to the next page
if ( next == $(starting_offer).data("start") ) {
window.location.href = "<?php echo $next_page; ?>";
}
});
要计算数字并显示广告,需要在服务器和客户端之间分配工作。这里的关键是服务器维护日常视图,而客户端请求日常视图并要求更新它们。
首先,您需要为客户端和服务器设置两个端点,以便通过https:进行通信
-
HttpPost www.example.com/advertiser-1/daily-views[告诉advertiser-1已被查看的服务器,因此每天都在增加视图]
-
HttpGet www.example.com/advertiser-1/daily-views[获取advertiser_1从服务器的每日浏览量]
在客户端,
-
您需要对服务器进行ajax调用(Get请求)来获取每日计数。
-
查看广告时,您需要向服务器发出ajax调用(Post请求),以更新广告商的每日视图。
在服务器端,
- 对于get请求,返回包含每日视图数的json对象
- 对于post请求,增加每日浏览次数并返回"ok"(或任何您想要的)
相关文章:
- 在JavaScript中重构上个月的第一天和最后一天的代码(node.js)
- 为什么new Date()会删除一天?-Javascript
- javascript创建减去一天的新日期
- Javascript和图像更改,基于一天中的时间
- 从'获取本月的最后一天;2015-02-23'字符串(javascript)
- SQL Server日期(不是日期时间)到JavaScript日期-休息一天
- 在 JSON/Javascript 中表示一天中的时间的首选方法
- 如何在 javascript 中获取指定时区的一天的开始时间和结束时间(以 UTC 为单位)
- JavaScript:获取每月的第一天和最后一天,格式为 YYYY.唰
- 使用 Javascript 根据星期几和一天中的时间显示 HTML 元素
- Javascript 表示一天中剩余的时间
- javascript 日期或下一个日期基于一天中的时间和 if/else
- 将一年中的某一天转换为当前日期
- 我如何限制广告商的次数'的广告在某一天用Javascript显示
- JavaScript 计算一年中的某一天 (1 - 366)
- 获取一个月中某一天的所有事件
- 获取某一天相对于给定日期的日期
- 获取一周中某一天的下一个日期
- 从一年中的某一天开始获取完整日期
- 一年中的一天Javascript代码赢得'我没有浏览过优秀的文本编辑器