Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gregt/lazy load #36

Merged
merged 5 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -241,6 +246,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 @@ -640,7 +649,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