2022-04-14 16:12:53 +02:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
|
|
|
import Button from 'component/button';
|
|
|
|
import I18nMessage from 'component/i18nMessage';
|
|
|
|
import * as PAGES from 'constants/pages';
|
|
|
|
import useShouldShowAds from 'effects/use-should-show-ads';
|
2022-06-07 21:16:26 +02:00
|
|
|
import { useIsMobile } from 'effects/use-screensize';
|
2022-04-14 16:12:53 +02:00
|
|
|
|
|
|
|
const AD_SCRIPT_URL = 'https://widgets.outbrain.com/outbrain.js';
|
|
|
|
|
2022-05-26 05:09:05 +02:00
|
|
|
const AD_CONFIG = {
|
|
|
|
AR_18: 'AR_18', // 5 tiles.
|
|
|
|
AR_60: 'AR_60', // 6 tiles. Doesn't work well on mobile (6 tiles compresses to 1, text only).
|
|
|
|
AR_3: 'AR_3', // 4 tiles on desktop, dynamic count on mobile.
|
|
|
|
};
|
|
|
|
|
2022-04-14 16:12:53 +02:00
|
|
|
// ****************************************************************************
|
|
|
|
// ****************************************************************************
|
|
|
|
|
|
|
|
const adsSignInDriver = (
|
|
|
|
<I18nMessage
|
|
|
|
tokens={{
|
|
|
|
sign_up_for_premium: (
|
|
|
|
<Button button="link" label={__('Get Odysee Premium+')} navigate={`/$/${PAGES.ODYSEE_MEMBERSHIP}`} />
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
%sign_up_for_premium% for an ad free experience.
|
|
|
|
</I18nMessage>
|
|
|
|
);
|
|
|
|
|
|
|
|
// ****************************************************************************
|
|
|
|
// AdsBanner
|
|
|
|
// ****************************************************************************
|
|
|
|
|
|
|
|
let gReferenceCounter = 0;
|
|
|
|
|
|
|
|
type Props = {
|
2022-05-30 12:50:15 +02:00
|
|
|
isAdBlockerFound: ?boolean,
|
2022-04-14 16:12:53 +02:00
|
|
|
userHasPremiumPlus: boolean,
|
|
|
|
userCountry: string,
|
|
|
|
currentTheme: string,
|
|
|
|
doSetAdBlockerFound: (boolean) => void,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function AdsBanner(props: Props) {
|
2022-05-30 12:50:15 +02:00
|
|
|
const { isAdBlockerFound, userHasPremiumPlus, userCountry, currentTheme, doSetAdBlockerFound } = props;
|
|
|
|
const shouldShowAds = useShouldShowAds(userHasPremiumPlus, userCountry, isAdBlockerFound, doSetAdBlockerFound);
|
2022-06-07 21:16:26 +02:00
|
|
|
const isMobile = useIsMobile();
|
2022-04-14 16:12:53 +02:00
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (shouldShowAds) {
|
|
|
|
try {
|
|
|
|
const script = document.createElement('script');
|
|
|
|
script.src = AD_SCRIPT_URL;
|
|
|
|
script.async = true;
|
|
|
|
script.onload = () => {
|
|
|
|
++gReferenceCounter;
|
|
|
|
};
|
|
|
|
|
|
|
|
// $FlowFixMe
|
|
|
|
document.body.appendChild(script);
|
|
|
|
return () => {
|
|
|
|
// $FlowFixMe
|
|
|
|
document.body.removeChild(script);
|
|
|
|
|
|
|
|
if (--gReferenceCounter <= 0) {
|
2022-05-13 06:14:13 +02:00
|
|
|
// Note: This method has the bad requirement of the parent having to
|
|
|
|
// mount and dismount all banners in the same cycle.
|
2022-04-14 16:12:53 +02:00
|
|
|
delete window.OBR;
|
|
|
|
// TODO: clear styles after the team adds an ID or class for us to query.
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
}, [shouldShowAds]);
|
|
|
|
|
|
|
|
if (!shouldShowAds) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="banner-ad">
|
2022-05-11 03:47:49 +02:00
|
|
|
<div className="banner-ad__driver">
|
|
|
|
<div className="banner-ad__driver-label">Ad</div>
|
|
|
|
<div className="banner-ad__driver-value">{adsSignInDriver}</div>
|
|
|
|
</div>
|
2022-04-14 16:12:53 +02:00
|
|
|
<div
|
|
|
|
className="banner-ad__container OUTBRAIN"
|
|
|
|
data-ob-contenturl="DROP_PERMALINK_HERE"
|
2022-06-07 21:16:26 +02:00
|
|
|
data-widget-id={!isMobile ? AD_CONFIG.AR_60 : AD_CONFIG.AR_18}
|
2022-04-14 16:12:53 +02:00
|
|
|
data-ob-installation-key="ADNIMKAJDGAG4GAO6AGG6H5KP"
|
|
|
|
data-dark-mode={currentTheme === 'dark' ? 'true' : 'false'}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|