Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Commit

Permalink
Gregt/lazy load (#36)
Browse files Browse the repository at this point in the history
* Add stuff for lazy load

* First shot at ignoring isInViewport response.

* Will render ads even if the inviewport check fails

* Removed commented out line of code

* Version bump and changelog update

---------

Co-authored-by: Andrew Sotiriou <[email protected]>
Co-authored-by: Greg Thorson <[email protected]>
  • Loading branch information
3 people committed Dec 18, 2023
1 parent f043ef7 commit 45a4ea3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<a name="2.1.9"></a>
## [2.1.9](https://github.com/apartmenttherapy/react-gpt/compare/v2.1.8...v2.1.9) (2023-05-10)

* disable viwability threshold check if lazyloading ([36] (https://github.com/apartmenttherapy/react-gpt/pull/36))

<a name="2.1.8"></a>
## [2.1.8](https://github.com/apartmenttherapy/react-gpt/compare/v2.1.7...v2.1.8) (2023-03-03)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@atmedia/react-gpt",
"version": "2.1.8",
"version": "2.1.9",
"description": "A react display ad component using Google Publisher Tag",
"main": "lib/index.js",
"jsnext:main": "es/index.js",
Expand Down
14 changes: 13 additions & 1 deletion src/Bling.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class Bling extends React.Component {
onImpressionViewable: PropTypes.func,
/**
* An optional event handler function for `googletag.events.slotVisibilityChangedEvent`.
* Note that this is independent of the isSlotInView function
*
* @property onSlotVisibilityChanged
*/
Expand All @@ -174,6 +175,10 @@ class Bling extends React.Component {
* @property viewableThreshold
*/
viewableThreshold: PropTypes.number,
/**
* Skip isInViewport check if true.
*/
doNotUseViewableThreshold: PropTypes.bool,
/**
* An optional call back function to notify when the script is loaded.
*
Expand Down Expand Up @@ -257,6 +262,10 @@ class Bling extends React.Component {
* An optional flag to indicate whether an ad should only render when it's fully in the viewport area. Default is `true`.
*/
renderWhenViewable: true,
/**
* If true skip isInViewport check.
*/
doNotUseViewableThreshold: false,
/**
* An optional number to indicate how much percentage of an ad area needs to be in a viewable area before rendering. Default value is 0.5.
* Acceptable range is between 0 and 1.
Expand Down Expand Up @@ -659,7 +668,10 @@ class Bling extends React.Component {

notInViewport(props = this.props, state = this.state) {
const {inViewport} = state;
return this.getRenderWhenViewable(props) && !inViewport;
return (
this.getRenderWhenViewable(props) &&
(!props.doNotUseViewableThreshold && !inViewport)
);
}

defineSlot() {
Expand Down
6 changes: 4 additions & 2 deletions src/createManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const pubadsAPI = [
"setTagForChildDirectedTreatment",
"clearTagForChildDirectedTreatment",
"setVideoContent",
"setForceSafeFrame"
"setForceSafeFrame",
"enableLazyLoad"
];

export const APIToCallBeforeServiceEnabled = [
Expand All @@ -36,7 +37,8 @@ export const APIToCallBeforeServiceEnabled = [
"enableSyncRendering",
"disableInitialLoad",
"collapseEmptyDivs",
"setCentering"
"setCentering",
"enableLazyLoad"
];

export class AdManager extends EventEmitter {
Expand Down

0 comments on commit 45a4ea3

Please sign in to comment.