2020-01-24 19:31:49 +01:00
|
|
|
// @flow
|
2022-03-15 03:38:45 +01:00
|
|
|
import { SHOW_ADS } from 'config';
|
2020-01-24 19:31:49 +01:00
|
|
|
import * as PAGES from 'constants/pages';
|
2020-01-23 17:21:36 +01:00
|
|
|
import React, { useEffect } from 'react';
|
2020-01-24 19:31:49 +01:00
|
|
|
import I18nMessage from 'component/i18nMessage';
|
|
|
|
import Button from 'component/button';
|
2020-03-26 22:47:07 +01:00
|
|
|
import classnames from 'classnames';
|
2022-04-14 14:04:22 +02:00
|
|
|
import { platform } from 'util/platform';
|
2022-05-18 13:16:35 +02:00
|
|
|
import Icon from 'component/common/icon';
|
|
|
|
import * as ICONS from 'constants/icons';
|
2021-01-23 22:21:25 +01:00
|
|
|
|
2022-03-07 07:31:53 +01:00
|
|
|
// prettier-ignore
|
|
|
|
const AD_CONFIGS = Object.freeze({
|
|
|
|
DEFAULT: {
|
|
|
|
url: 'https://cdn.vidcrunch.com/integrations/618bb4d28aac298191eec411/Lbry_Odysee.com_Responsive_Floating_DFP_Rev70_1011.js',
|
|
|
|
tag: 'vidcrunchJS537102317',
|
|
|
|
},
|
|
|
|
MOBILE: {
|
|
|
|
url: 'https://cdn.vidcrunch.com/integrations/618bb4d28aac298191eec411/Lbry_Odysee.com_Mobile_Floating_DFP_Rev70_1611.js',
|
|
|
|
tag: 'vidcrunchJS199212779',
|
|
|
|
},
|
|
|
|
EU: {
|
|
|
|
url: 'https://tg1.vidcrunch.com/api/adserver/spt?AV_TAGID=61dff05c599f1e20b01085d4&AV_PUBLISHERID=6182c8993c8ae776bd5635e9',
|
|
|
|
tag: 'AV61dff05c599f1e20b01085d4',
|
|
|
|
},
|
|
|
|
});
|
2022-01-14 20:21:17 +01:00
|
|
|
|
2022-03-14 18:49:15 +01:00
|
|
|
// Internal use only. One-time update flag.
|
|
|
|
let ad_blocker_detected;
|
|
|
|
|
2020-01-24 19:31:49 +01:00
|
|
|
type Props = {
|
2020-03-26 22:47:07 +01:00
|
|
|
type: string,
|
2022-03-07 13:11:28 +01:00
|
|
|
tileLayout?: boolean,
|
2020-03-26 22:47:07 +01:00
|
|
|
small: boolean,
|
2021-03-21 20:02:50 +01:00
|
|
|
claim: Claim,
|
2021-01-31 04:47:06 +01:00
|
|
|
isMature: boolean,
|
2022-03-09 19:05:37 +01:00
|
|
|
userHasPremiumPlus: boolean,
|
2022-03-07 13:11:28 +01:00
|
|
|
className?: string,
|
2022-03-14 18:49:15 +01:00
|
|
|
doSetAdBlockerFound: (boolean) => void,
|
2020-01-24 19:31:49 +01:00
|
|
|
};
|
|
|
|
|
2021-12-02 19:22:51 +01:00
|
|
|
function removeIfExists(querySelector) {
|
|
|
|
const element = document.querySelector(querySelector);
|
|
|
|
if (element) element.remove();
|
|
|
|
}
|
|
|
|
|
2020-01-24 19:31:49 +01:00
|
|
|
function Ads(props: Props) {
|
2022-03-14 18:49:15 +01:00
|
|
|
const { type = 'video', tileLayout, small, userHasPremiumPlus, className, doSetAdBlockerFound } = props;
|
2022-03-09 19:05:37 +01:00
|
|
|
|
2022-03-10 14:38:19 +01:00
|
|
|
const [shouldShowAds, setShouldShowAds] = React.useState(resolveAdVisibility());
|
2022-04-14 14:04:22 +02:00
|
|
|
const mobileAds = platform.isAndroid() || platform.isIOS();
|
2022-01-04 17:55:59 +01:00
|
|
|
|
2022-01-14 20:21:17 +01:00
|
|
|
// this is populated from app based on location
|
2022-03-07 07:31:53 +01:00
|
|
|
const isInEu = localStorage.getItem('gdprRequired') === 'true';
|
2022-03-09 10:53:58 +01:00
|
|
|
const adConfig = isInEu ? AD_CONFIGS.EU : mobileAds ? AD_CONFIGS.MOBILE : AD_CONFIGS.DEFAULT;
|
2021-11-23 16:21:33 +01:00
|
|
|
|
2022-03-10 14:38:19 +01:00
|
|
|
function resolveAdVisibility() {
|
2022-03-14 18:49:15 +01:00
|
|
|
// 'ad_blocker_detected' will be undefined at startup. Wait until we are
|
|
|
|
// sure it is not blocked (i.e. === false) before showing the component.
|
|
|
|
return ad_blocker_detected === false && SHOW_ADS && !userHasPremiumPlus;
|
2022-03-10 14:38:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
2022-03-14 18:49:15 +01:00
|
|
|
if (ad_blocker_detected === undefined) {
|
2022-03-10 14:38:19 +01:00
|
|
|
let mounted = true;
|
|
|
|
const GOOGLE_AD_URL = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
|
|
|
|
|
|
|
|
fetch(GOOGLE_AD_URL)
|
2022-03-14 19:25:51 +01:00
|
|
|
.then((response) => {
|
2022-03-14 18:49:15 +01:00
|
|
|
const detected = response.redirected === true;
|
|
|
|
window.odysee_ad_blocker_detected = detected;
|
|
|
|
ad_blocker_detected = detected;
|
|
|
|
doSetAdBlockerFound(detected);
|
2022-03-10 14:38:19 +01:00
|
|
|
})
|
|
|
|
.catch(() => {
|
2022-03-14 18:49:15 +01:00
|
|
|
ad_blocker_detected = true;
|
|
|
|
doSetAdBlockerFound(true);
|
2022-03-10 14:38:19 +01:00
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
if (mounted) {
|
|
|
|
setShouldShowAds(resolveAdVisibility());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
mounted = false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}, []);
|
|
|
|
|
2021-11-30 23:01:03 +01:00
|
|
|
// add script to DOM
|
2020-01-23 17:21:36 +01:00
|
|
|
useEffect(() => {
|
2022-01-04 17:55:59 +01:00
|
|
|
if (shouldShowAds) {
|
2021-01-22 00:57:29 +01:00
|
|
|
let script;
|
2020-03-26 22:47:07 +01:00
|
|
|
try {
|
2021-11-23 16:21:33 +01:00
|
|
|
script = document.createElement('script');
|
2022-03-07 07:31:53 +01:00
|
|
|
script.src = adConfig.url;
|
2020-03-26 22:47:07 +01:00
|
|
|
// $FlowFixMe
|
2021-12-01 04:17:28 +01:00
|
|
|
document.head.appendChild(script);
|
2020-03-26 22:47:07 +01:00
|
|
|
|
2021-11-30 23:01:03 +01:00
|
|
|
return () => {
|
2020-02-05 06:13:29 +01:00
|
|
|
// $FlowFixMe
|
2021-11-30 23:01:03 +01:00
|
|
|
document.head.removeChild(script);
|
2022-03-10 13:07:35 +01:00
|
|
|
|
|
|
|
// clear aniview state to allow ad reload
|
|
|
|
delete window.aniplayerPos;
|
|
|
|
delete window.storageAni;
|
|
|
|
delete window.__VIDCRUNCH_CONFIG_618bb4d28aac298191eec411__;
|
|
|
|
delete window.__player_618bb4d28aac298191eec411__;
|
|
|
|
|
|
|
|
// clean DOM elements from ad related elements
|
|
|
|
removeIfExists('[src^="https://cdn.vidcrunch.com/618bb4d28aac298191eec411.js"]');
|
|
|
|
removeIfExists('[src^="https://player.aniview.com/script/6.1/aniview.js"]');
|
|
|
|
removeIfExists('[id^="AVLoaderaniplayer_vidcrunch"]');
|
|
|
|
removeIfExists('#av_css_id');
|
2021-11-30 23:01:03 +01:00
|
|
|
};
|
|
|
|
} catch (e) {}
|
2020-02-05 06:13:29 +01:00
|
|
|
}
|
2022-03-10 14:38:19 +01:00
|
|
|
}, [shouldShowAds]);
|
2020-03-26 22:47:07 +01:00
|
|
|
|
|
|
|
const adsSignInDriver = (
|
|
|
|
<I18nMessage
|
|
|
|
tokens={{
|
2022-03-15 03:38:45 +01:00
|
|
|
sign_up_for_premium: (
|
|
|
|
<Button button="link" label={__('Get Odysee Premium+')} navigate={`/$/${PAGES.ODYSEE_MEMBERSHIP}`} />
|
2020-03-26 22:47:07 +01:00
|
|
|
),
|
|
|
|
}}
|
|
|
|
>
|
2022-05-18 13:16:35 +02:00
|
|
|
%sign_up_for_premium% for an ad free experience.
|
2020-03-26 22:47:07 +01:00
|
|
|
</I18nMessage>
|
|
|
|
);
|
2020-01-23 17:21:36 +01:00
|
|
|
|
2022-03-07 13:11:28 +01:00
|
|
|
if (shouldShowAds && type === 'video') {
|
|
|
|
return (
|
2020-03-26 22:47:07 +01:00
|
|
|
<div
|
2022-03-07 13:11:28 +01:00
|
|
|
className={classnames('ads ads__claim-item', className, {
|
2022-03-09 09:02:11 +01:00
|
|
|
'ads__claim-item--tile': tileLayout,
|
2020-03-26 22:47:07 +01:00
|
|
|
})}
|
|
|
|
>
|
2022-03-07 13:11:28 +01:00
|
|
|
<div className="ad__container">
|
|
|
|
<div id={adConfig.tag} />
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
className={classnames('ads__claim-text', {
|
|
|
|
'ads__claim-text--small': small,
|
|
|
|
})}
|
|
|
|
>
|
2022-05-18 13:16:35 +02:00
|
|
|
<div className="ads__title">
|
|
|
|
{__('Ad')}
|
|
|
|
<br />
|
|
|
|
{__('Hate these?')}
|
|
|
|
{/* __('No ads, a custom badge and access to exclusive features, try Odysee Premium!') */}
|
|
|
|
</div>
|
|
|
|
<div className="ads__subtitle">
|
|
|
|
<Icon icon={ICONS.UPGRADE} />
|
|
|
|
{adsSignInDriver}
|
|
|
|
</div>
|
2022-03-07 13:11:28 +01:00
|
|
|
</div>
|
2020-03-26 22:47:07 +01:00
|
|
|
</div>
|
2022-03-07 13:11:28 +01:00
|
|
|
);
|
2021-01-22 00:57:29 +01:00
|
|
|
}
|
2022-01-04 18:43:35 +01:00
|
|
|
|
2022-03-07 13:11:28 +01:00
|
|
|
return null;
|
2022-01-04 18:43:35 +01:00
|
|
|
}
|
|
|
|
|
2022-03-15 03:38:45 +01:00
|
|
|
export default Ads;
|