Show Sticky in Content and Channel Page for incognito
https://odysee-workspace.slack.com/archives/C02G20Z2AEL/p1654171314724029?thread_ts=1654089384.715699&cid=C02G20Z2AEL Content: not showing ads for signed-in users because it interferes with commenting. Channel: same behavior as Categories (i.e. show is not Premium+).
This commit is contained in:
parent
9787940bc8
commit
70ddd08df6
3 changed files with 45 additions and 22 deletions
|
@ -560,7 +560,7 @@ function App(props: Props) {
|
|||
{getStatusNag()}
|
||||
</React.Suspense>
|
||||
|
||||
<AdsSticky />
|
||||
<AdsSticky uri={uri} />
|
||||
</React.Fragment>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
@ -1,16 +1,25 @@
|
|||
import { connect } from 'react-redux';
|
||||
import AdsSticky from './view';
|
||||
import { doSetAdBlockerFound } from 'redux/actions/app';
|
||||
import { selectClaimForUri } from 'redux/selectors/claims';
|
||||
import { selectAdBlockerFound } from 'redux/selectors/app';
|
||||
import { selectHomepageData } from 'redux/selectors/settings';
|
||||
import { selectOdyseeMembershipIsPremiumPlus, selectUserCountry } from 'redux/selectors/user';
|
||||
import AdsSticky from './view';
|
||||
import { selectOdyseeMembershipIsPremiumPlus, selectUserCountry, selectUserVerifiedEmail } from 'redux/selectors/user';
|
||||
import { isChannelClaim, isStreamPlaceholderClaim } from 'util/claim';
|
||||
|
||||
const select = (state, props) => ({
|
||||
const select = (state, props) => {
|
||||
const claim = selectClaimForUri(state, props.uri);
|
||||
|
||||
return {
|
||||
isContentClaim: isStreamPlaceholderClaim(claim) || Boolean(claim?.value?.source?.media_type),
|
||||
isChannelClaim: isChannelClaim(claim),
|
||||
authenticated: selectUserVerifiedEmail(state),
|
||||
isAdBlockerFound: selectAdBlockerFound(state),
|
||||
userHasPremiumPlus: selectOdyseeMembershipIsPremiumPlus(state),
|
||||
userCountry: selectUserCountry(state),
|
||||
homepageData: selectHomepageData(state),
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
const perform = {
|
||||
doSetAdBlockerFound,
|
||||
|
|
|
@ -12,6 +12,11 @@ const OUTBRAIN_CONTAINER_KEY = 'outbrainSizeDiv';
|
|||
let gScript;
|
||||
|
||||
type Props = {
|
||||
uri: ?string,
|
||||
// --- redux ---
|
||||
isContentClaim: boolean,
|
||||
isChannelClaim: boolean,
|
||||
authenticated: ?boolean,
|
||||
isAdBlockerFound: ?boolean,
|
||||
userHasPremiumPlus: boolean,
|
||||
userCountry: string,
|
||||
|
@ -20,24 +25,35 @@ type Props = {
|
|||
};
|
||||
|
||||
export default function AdsSticky(props: Props) {
|
||||
const { isAdBlockerFound, userHasPremiumPlus, userCountry, homepageData, doSetAdBlockerFound } = props;
|
||||
const {
|
||||
isContentClaim,
|
||||
isChannelClaim,
|
||||
authenticated,
|
||||
isAdBlockerFound,
|
||||
userHasPremiumPlus,
|
||||
userCountry,
|
||||
homepageData,
|
||||
doSetAdBlockerFound,
|
||||
} = props;
|
||||
|
||||
const { location } = useHistory();
|
||||
const [refresh, setRefresh] = React.useState(0);
|
||||
|
||||
const inAllowedPath = isPathAllowed(location.pathname);
|
||||
// Global condition on whether ads should be activated:
|
||||
const shouldShowAds = useShouldShowAds(userHasPremiumPlus, userCountry, isAdBlockerFound, doSetAdBlockerFound);
|
||||
const shouldLoadSticky = inAllowedPath && !gScript && !inIFrame() && !platform.isMobile();
|
||||
// Global conditions aside, should the Sticky be shown for this path:
|
||||
const inAllowedPath = shouldShowAdsForPath(location.pathname, isContentClaim, isChannelClaim, authenticated);
|
||||
// Final answer:
|
||||
const shouldLoadSticky = shouldShowAds && inAllowedPath && !gScript && !inIFrame() && !platform.isMobile();
|
||||
|
||||
function isPathAllowed(pathname) {
|
||||
const categoryValues = Object.values(homepageData);
|
||||
function shouldShowAdsForPath(pathname, isContentClaim, isChannelClaim, authenticated) {
|
||||
// $FlowIssue: mixed type
|
||||
const pathIsCategory = categoryValues.some((x) => pathname.startsWith(`/$/${x?.name}`));
|
||||
return pathIsCategory;
|
||||
const pathIsCategory = Object.values(homepageData).some((x) => pathname.startsWith(`/$/${x?.name}`));
|
||||
return pathIsCategory || isChannelClaim || (isContentClaim && !authenticated);
|
||||
}
|
||||
|
||||
// -- Mount script; 1 per session.
|
||||
React.useEffect(() => {
|
||||
if (shouldShowAds && shouldLoadSticky) {
|
||||
if (shouldLoadSticky) {
|
||||
gScript = document.createElement('script');
|
||||
gScript.src = 'https://adncdnend.azureedge.net/adtags/odysee.adn.js';
|
||||
gScript.async = true;
|
||||
|
@ -45,9 +61,8 @@ export default function AdsSticky(props: Props) {
|
|||
// $FlowFixMe
|
||||
document.body.appendChild(gScript);
|
||||
}
|
||||
}, [shouldShowAds, shouldLoadSticky]);
|
||||
}, [shouldLoadSticky]);
|
||||
|
||||
// -- Update visibility per pathname
|
||||
React.useEffect(() => {
|
||||
const container = window[OUTBRAIN_CONTAINER_KEY];
|
||||
if (container) {
|
||||
|
@ -55,8 +70,7 @@ export default function AdsSticky(props: Props) {
|
|||
}
|
||||
}, [inAllowedPath, refresh]);
|
||||
|
||||
// Nothing for us to mount; the ad script will handle everything.
|
||||
return null;
|
||||
return null; // Nothing for us to mount; the ad script will handle everything.
|
||||
}
|
||||
|
||||
// ****************************************************************************
|
||||
|
|
Loading…
Reference in a new issue