Skip to content

Commit 20eba92

Browse files
authored
[DA] Implement auto refresh limit (#128)
1 parent 18268d9 commit 20eba92

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "adjs",
3-
"version": "2.0.0-beta.31",
3+
"version": "2.0.0-beta.32",
44
"description": "Ad Library to simplify and optimize integration with ad networks such as DFP",
55
"main": "./core.js",
66
"types": "./types.d.ts",

src/plugins/AutoRefresh.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class AutoRefresh extends GenericPlugin {
1111

1212
// SetInterval Reference
1313
private timerReference?: number;
14+
// Number of times the ad refreshed.
15+
private refreshCount: number = 0;
1416

1517
public afterRender() {
1618
dispatchEvent(this.ad.id, LOG_LEVELS.INFO, 'AutoRefresh Plugin', 'Adding monitoring for ad.');
@@ -47,7 +49,7 @@ class AutoRefresh extends GenericPlugin {
4749
return;
4850
}
4951

50-
const { refreshRateInSeconds = 30 } = this.ad.configuration;
52+
const { refreshRateInSeconds = 30, refreshLimit = null } = this.ad.configuration;
5153
dispatchEvent(
5254
this.ad.id,
5355
LOG_LEVELS.INFO,
@@ -59,8 +61,15 @@ class AutoRefresh extends GenericPlugin {
5961
this.timeInView += 1;
6062

6163
// Determine whether the ad should refresh
62-
if (!this.isRefreshing && this.timeInView >= refreshRateInSeconds) {
64+
const underRefreshLimit = (refreshLimit === null || this.refreshCount < refreshLimit);
65+
if (!this.isRefreshing && this.timeInView >= refreshRateInSeconds && underRefreshLimit) {
6366
this.isRefreshing = true;
67+
this.refreshCount += 1;
68+
69+
// Once we hit the limit, clear the interval.
70+
if (this.refreshCount === refreshLimit) {
71+
clearInterval(this.timerReference);
72+
}
6473

6574
dispatchEvent(
6675
this.ad.id,

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ export interface IAdConfiguration {
177177
plugins?: IPluginConstructorOrSingleton[];
178178
refreshOnBreakpoint?: boolean;
179179
refreshRateInSeconds?: number;
180+
refreshLimit?: number;
180181
sizes?: AdSizes;
181182
targeting?: IAdTargeting;
182183
}

0 commit comments

Comments
 (0)