diff --git a/config/default.json b/config/default.json index 2b281dca2d..7f49ab251d 100644 --- a/config/default.json +++ b/config/default.json @@ -73,79 +73,93 @@ }, "gpt_enabled": null, "gpt_basic_slots": { - "top_nav_premium": { - "slot_id": "div-gpt-ad-1548778664403-0", - "args": ["/21784675435/steemit_top-navi", [[220, 90], [728, 90], [970, 90]], "div-gpt-ad-1548778664403-0"], - "kind": "basic" - }, - "top_nav": { - "slot_id": "div-gpt-ad-1548778612404-0", - "args": ["/21784675435/steemit_premium_top-navi", [[970, 90], [728, 90], [220, 90]], "div-gpt-ad-1548778612404-0"], - "kind": "basic" - }, - "left_nav_premium": { - "slot_id": "div-gpt-ad-1548778771262-0", - "args": ["/21784675435/steemit_premium_left-navigation", [[125, 125], [120, 90], [120, 600], [120, 60], [160, 600], [120, 240]], "div-gpt-ad-1548778771262-0"], - "kind": "basic" - }, - "left_nav": { - "slot_id": "div-gpt-ad-1548778799404-0", - "args": ["/21784675435/steemit_left-navigation", [[160, 600], [120, 240], [120, 600], [120, 60], [125, 125], [120, 90]], "div-gpt-ad-1548778799404-0"], - "kind": "basic" - }, - "right_nav": { - "slot_id": "div-gpt-ad-1548778861089-0", - "args": ["/21784675435/steemit_right-navigation", [[120, 600], [120, 60], [125, 125], [120, 240], [160, 600], [120, 90]], "div-gpt-ad-1548778861089-0"], - "kind": "basic" - }, - "bottom_post": { - "slot_id": "div-gpt-ad-1553686705417-0", - "args": ["/21784675435/steemit_bottom-of-post", [[300, 100], [234, 60], [728, 90], [220, 90], [970, 90], [336, 280], [890, 222], [320, 50], [468, 60]], "div-gpt-ad-1553686705417-0"] - }, - "basic_bottom_post": { - "slot_id": "div-gpt-ad-1553686705417-0", - "args": ["/21784675435/steemit_bottom-of-post", [[300, 100], [234, 60], [728, 90], [220, 90], [970, 90], [336, 280], [890, 222], [320, 50], [468, 60]], "div-gpt-ad-1553686705417-0"] - }, - "in_feed": { - "slot_id": "div-gpt-ad-1548778917304-0", - "args": ["/21784675435/steemit_in-feed", [[728, 90], [300, 100], [890, 222], [468, 60], [970, 90], [336, 280], [234, 60]], "div-gpt-ad-1548778917304-0"], - "kind": "basic" - } - }, - "gpt_category_slots": { - "cryptocurrency": { - "top_nav": { - "slot_id": "div-gpt-ad-1550891917103-0", - "args": ["/21784675435/steemit_top-navi/steemit_top-navi_cryptocurrency", [[728, 90], [220, 90], [970, 90]], "div-gpt-ad-1550891917103-0"], - "kind": "category" - }, - "right_nav": { - "slot_id": "div-gpt-ad-1550892019550-0", - "args": ["/21784675435/steemit_right-navigation/steemit_right-navigation_cryptocurrency", [[120, 90], [120, 240], [120, 60], [160, 600], [120, 600], [125, 125]], "div-gpt-ad-1550892019550-0"], - "kind": "category" - }, - "left_nav": { - "slot_id": "div-gpt-ad-1550892097245-0", - "args": ["/21784675435/steemit_left-navigation/steemit_left-navigation_cryptocurrency", [[120, 240], [120, 600], [125, 125], [120, 90], [160, 600], [120, 60]], "div-gpt-ad-1550892097245-0"], - "kind": "category" - }, - "bottom_post": { - "slot_id": "div-gpt-ad-1550892163180-0", - "args": ["/21784675435/steemit_bottom-of-post/steemit_bottom-of-post_cryptocurrency", [[336, 280], [320, 50], [468, 60], [970, 90], [890, 222], [300, 100], [728, 90], [234, 60]], "div-gpt-ad-1550892163180-0"], - "kind": "category" - } + "bottom-of-post": { + "path": "/21784675435/steemit_bottom-of-post", + "dimensions": [[728, 90], [970, 90]] + }, + "bottom-of-post-mobile": { + "path": "/21784675435/steemit_bottom-of-post/steemit_bottom-of-post_mobile", + "dimensions": [[220, 90]] + }, + + "left-navigation": { + "path": "/21784675435/steemit_left-navigation", + "dimensions": [[120, 600], [160, 600]] + }, + "left-navigation-loggedin-mobile": { + "path": "/21784675435/steemit_left-navigation/steemit_left-navigation_loggedin_mobile", + "dimensions": [[120, 240]] + }, + "left-navigation-loggedin": { + "path": "/21784675435/steemit_left-navigation/steemit_left-navigation_loggedin", + "dimensions": [[120, 600], [160, 600]] + }, + "left-navigation-mobile": { + "path": "/21784675435/steemit_left-navigation/steemit_left-navigation_mobile", + "dimensions": [[120, 240]] + }, + + "right-navigation": { + "path": "/21784675435/steemit_right-navigation", + "dimensions": [[120, 600], [160, 600]] + }, + "right-navigation-loggedin-mobile": { + "path": "/21784675435/steemit_right-navigation/steemit_right-navigation_loggedin_mobile", + "dimensions": [[120, 240]] + }, + "right-navigation-loggedin": { + "path": "/21784675435/steemit_right-navigation/steemit_right-navigation_loggedin", + "dimensions": [[120, 600], [160, 600]] + }, + "right-navigation-mobile": { + "path": "/21784675435/steemit_right-navigation/steemit_right-navigation_mobile", + "dimensions": [[120, 240]] + }, + + "top-navigation": { + "path": "/21784675435/steemit_top-navi", + "dimensions": [[728, 90], [970, 90]] + }, + "top-navigation-loggedin-mobile": { + "path": "/21784675435/steemit_top-navi/steemit_top-navi_loggedin_mobile", + "dimensions": [[220, 90]] + }, + "top-navigation-loggedin": { + "path": "/21784675435/steemit_top-navi/steemit_top-navi_loggedin", + "dimensions": [[728, 90], [970, 90]] + }, + "top-navigation-mobile": { + "path": "/21784675435/steemit_top-navi/steemit_top-navi_mobile", + "dimensions": [[220, 90]] } }, + "gpt_category_slots": {}, "gpt_bidding_slots":{ - "left_nav_2": { - "slot_id": "div-gpt-ad-1554687231046-0", - "args": ["/21784675435/steemit_left-navigation/steemit_left-navigation_prebid", [[120, 600],[160,600]], "div-gpt-ad-1554687231046-0"], - "kind": "bidding" - }, - "bottom_post": { - "slot_id": "div-gpt-ad-1551233873698-0", - "args": ["/21784675435/steemit_bottom-of-post/steemit_bottom-of-post_prebid", [[728, 90], [320, 50], [234, 60], [336, 280], [970, 90], [468, 60], [300, 100], [890, 222]], "div-gpt-ad-1551233873698-0"], - "kind": "bidding" + "bottom-of-post": { + "path": "/21784675435/steemit_bottom-of-post/steemit_bottom-of-post_prebid", + "dimensions": [[728, 90]] + }, + + "post-page-above-comments": { + "path": "/21784675435/steemit_post-page-above-comments", + "dimensions": [[728, 90], [970, 90]] + }, + "post-page-above-comments-loggedin-mobile": { + "path": "/21784675435/steemit_post-page-above-comments/steemit_post-page-above-comments_loggedin_mobile", + "dimensions": [[220, 90]] + }, + "post-page-above-comments-loggedin": { + "path": "/21784675435/steemit_post-page-above-comments/steemit_post-page-above-comments_loggedin", + "dimensions": [[728, 90], [970, 90]] + }, + "post-page-above-comments-mobile": { + "path": "/21784675435/steemit_post-page-above-comments/steemit_post-page-above-comments_mobile", + "dimensions": [[220, 90]] + }, + + "left-navigation": { + "path": "/21784675435/steemit_left-navigation/steemit_left-navigation_prebid", + "dimensions": [[120, 600], [160, 600]] } }, "gpt_bidding": { @@ -153,16 +167,16 @@ "failsafe_timeout": 3000, "ad_units": [ { - "code": "div-gpt-ad-1551233873698-0", - "mediaTypes": { "banner": { "sizes": [728, 90] } }, + "code": "/21784675435/steemit_post-page-above-comments", + "mediaTypes": { "banner": { "sizes": [[728, 90], [220, 90], [970, 90]] } }, "bids": [{ "bidder": "coinzilla", "params": { "placementId": "6425c7b9886e0045972" } }] }, { - "code": "div-gpt-ad-1551234081752-0", - "mediaTypes": { "banner": { "sizes": [160, 600] } }, + "code": "/21784675435/steemit_left-navigation/steemit_left-navigation_prebid", + "mediaTypes": { "banner": { "sizes": [[120, 600], [160, 600]] } }, "bids": [{ "bidder": "coinzilla", "params": { "placementId": "3575c7b9886e2cb3619" } diff --git a/src/app/components/App.jsx b/src/app/components/App.jsx index b925a97fd6..8920e534c7 100644 --- a/src/app/components/App.jsx +++ b/src/app/components/App.jsx @@ -35,12 +35,30 @@ class App extends React.Component { this.setState({ gptBannerHeight: height }); } + toggleBodyNightmode(nightmodeEnabled) { + if (nightmodeEnabled) { + document.body.classList.remove('theme-light'); + document.body.classList.add('theme-dark'); + } else { + document.body.classList.remove('theme-dark'); + document.body.classList.add('theme-light'); + } + } + + componentWillReceiveProps(nextProps) { + const { nightmodeEnabled } = nextProps; + this.toggleBodyNightmode(nightmodeEnabled); + } + componentWillMount() { if (process.env.BROWSER) localStorage.removeItem('autopost'); // July 14 '16 compromise, renamed to autopost2 this.props.loginUser(); } componentDidMount() { + const { nightmodeEnabled } = this.props; + this.toggleBodyNightmode(nightmodeEnabled); + window.addEventListener('gptadshown', this.gptadshownListener); } diff --git a/src/app/components/elements/AuthorDropdown.scss b/src/app/components/elements/AuthorDropdown.scss index 4ab2b094bc..e89e46639b 100644 --- a/src/app/components/elements/AuthorDropdown.scss +++ b/src/app/components/elements/AuthorDropdown.scss @@ -50,6 +50,8 @@ clear: both; font-size: 90%; padding-top: 15px; + overflow: hidden; + text-overflow: ellipsis; } } } diff --git a/src/app/components/elements/BiddingAd.jsx b/src/app/components/elements/BiddingAd.jsx index d200908486..966c729400 100644 --- a/src/app/components/elements/BiddingAd.jsx +++ b/src/app/components/elements/BiddingAd.jsx @@ -3,63 +3,107 @@ import { connect } from 'react-redux'; class BiddingAd extends Component { componentDidMount() { - window.addEventListener('prebidNoBids', this.prebidNoBids); - const id = this.id; - googletag.cmd.push(function() { - console.log( - 'BiddingAd::componentDidMount::2nd googletag push with display' + if (!this.ad.path || !this.enabled) return; + + googletag.cmd.push(() => { + const slot = googletag.defineSlot( + this.ad.path, + this.ad.dimensions, + this.ad.path ); - googletag.display(id); - }); - } - componentWillUnmount() { - window.removeEventListener('prebidNoBids', this.prebidNoBids); + if (slot) { + slot.addService(googletag.pubads()); + googletag.pubads().enableSingleRequest(); + googletag.enableServices(); + + googletag.cmd.push(() => { + googletag.display(this.ad.path); + this.refreshBid(this.ad.path, slot); + }); + } + }); } - prebidNoBids(e) { - console.log('Received a NOBIDS event', e, this.state); - if (e.slotId === this.id) { - console.log('Will hide this ad based on event match id', e); - this.setState({ shown: false }); - } + refreshBid(path, slot) { + pbjs.que.push(() => { + pbjs.requestBids({ + timeout: 2000, + adUnitCodes: [path], + bidsBackHandler: function() { + pbjs.setTargetingForGPTAsync([path]); + googletag.pubads().refresh([slot]); + }, + }); + }); } constructor(props) { super(props); - this.id = this.props.id; - this.state = { shown: true }; + const { ad, enabled, type } = props; - this.prebidNoBids = this.prebidNoBids.bind(this); - } + this.ad = {}; + this.type = type; + this.enabled = false; - render() { - console.log('BiddingAd::render'); - if (this.state.shown) { - console.log('WILL SHOW A BIDDING AD!!!!!!!!!!!!!!!!!'); - return ( -
-
-
- ); + if (ad) { + // console.info( + // `Slot named '${props.slotName}' will render with given data:`, + // ad + // ); + this.enabled = enabled; + this.ad = ad.toJS(); } else { - // TODO: One Day we will fall back to another ad type here. - console.log('NO AD TO SHOW!'); - return null; + // console.info( + // `Slot named '${ + // props.slotName + // }' will be disabled because we were unable to find the ad details.` + // ); } } + + render() { + return ( +
+ ); + } } BiddingAd.propTypes = { - id: PropTypes.string.isRequired, // TODO: This is the naive way, make this better with a sensible config. + ad: PropTypes.shape({ + path: PropTypes.string, + dimensions: PropTypes.array, + }).isRequired, + enabled: PropTypes.bool.isRequired, type: PropTypes.oneOf(['Bidding', 'Category', 'Basic']), }; export default connect( (state, props) => { - console.log('GptBidding::connect', props); + const enabled = + !!state.app.getIn(['googleAds', 'gptEnabled']) && + !!process.env.BROWSER && + !!window.googletag; + const postCategory = state.global.get('postCategory'); + const basicSlots = state.app.getIn(['googleAds', `gptBasicSlots`]); + const biddingSlots = state.app.getIn(['googleAds', `gptBiddingSlots`]); + const categorySlots = state.app.getIn([ + 'googleAds', + `gptCategorySlots`, + ]); + + const slotName = props.slotName; + let type = props.type; + let slot = state.app.getIn(['googleAds', `gpt${type}Slots`, slotName]); + console.log('Found slot for type', type, slot); return { + enabled, + ad: slot, ...props, }; }, diff --git a/src/app/components/elements/GptAd.jsx b/src/app/components/elements/GptAd.jsx index 1a14dfd9b9..60b0c525e8 100644 --- a/src/app/components/elements/GptAd.jsx +++ b/src/app/components/elements/GptAd.jsx @@ -3,23 +3,26 @@ import { connect } from 'react-redux'; class GptAd extends Component { componentDidMount() { - if (!this.ad.slot_id || !this.enabled) { - return; - } + if (!this.ad.path || !this.enabled) return; googletag.cmd.push(() => { - const slot = googletag.defineSlot(...this.ad.args); + const slot = googletag.defineSlot( + this.ad.path, + this.ad.dimensions, + this.ad.path + ); if (slot) { slot.addService(googletag.pubads()); + googletag.pubads().enableSingleRequest(); + googletag.enableServices(); googletag.cmd.push(() => { - googletag.display(this.ad.slot_id); + googletag.display(this.ad.path); googletag.pubads().refresh([slot]); googletag .pubads() .addEventListener('slotRenderEnded', event => { - console.info('Slot has been rendered:', event); window.dispatchEvent(new Event('gptadshown')); }); }); @@ -36,18 +39,18 @@ class GptAd extends Component { this.enabled = false; if (ad) { - console.info( - `Slot named '${props.slotName}' will render with given data:`, - ad - ); + // console.info( + // `Slot named '${props.slotName}' will render with given data:`, + // ad + // ); this.enabled = enabled; this.ad = ad.toJS(); } else { - console.info( - `Slot named '${ - props.slotName - }' will be disabled because we were unable to find the ad details.` - ); + // console.info( + // `Slot named '${ + // props.slotName + // }' will be disabled because we were unable to find the ad details.` + // ); } } @@ -55,27 +58,22 @@ class GptAd extends Component { if (!this.ad || !this.enabled) { return
; } - // else if (this.type == 'Bidding') { - // return( - // - // - // div-gpt-ad-1551233873698-0 - // - // ) - // } return (
); } } GptAd.propTypes = { - ad: PropTypes.object.isRequired, //TODO: Define this shape + ad: PropTypes.shape({ + path: PropTypes.string, + dimensions: PropTypes.array, + }).isRequired, enabled: PropTypes.bool.isRequired, type: PropTypes.oneOf(['Bidding', 'Category', 'Basic']), }; @@ -94,48 +92,9 @@ export default connect( `gptCategorySlots`, ]); - // Determine which type of ad to show - // - // * Show a bidding ad if it's a bidding ad (e.g. Coinzilla) - // * Show a category ad (an ad on just #cryptocurrency, for example) - // * Fall back to a regular GPT ad - // const slotName = props.slotName; - let type = props.type; - - // let slot = basicSlots.getIn([slotName]); let slot = state.app.getIn(['googleAds', `gpt${type}Slots`, slotName]); - //console.log('GOT TYPE OF', type, slot); - // if (categorySlots.getIn([postCategory, slotName])) { - // console.info( - // `GPT-[${slotName}]::Overriding type of '${ - // type - // }' to be 'category' due to category being set to '${ - // postCategory - // }' and the existence of a category named '${ - // postCategory - // }' which has a slot named '${slotName}'` - // ); - // type = 'category'; - // slot = categorySlots.getIn([postCategory, slotName]); - // } else if (biddingSlots.getIn([slotName])) { - // console.info( - // `GPT-[${slotName}]::Overriding type of '${ - // type - // }' to be 'bidding' because we have a bidding slot defined for slotName '${ - // slotName - // }'` - // ); - // type = 'bidding'; - // slot = biddingSlots.getIn([slotName]); - // } else { - // console.info( - // `GPT-[${slotName}]::No override for type. Sticking with '${ - // type - // }'` - // ); - // } return { enabled, diff --git a/src/app/components/modules/Header/index.jsx b/src/app/components/modules/Header/index.jsx index db684d94fa..34836c2d37 100644 --- a/src/app/components/modules/Header/index.jsx +++ b/src/app/components/modules/Header/index.jsx @@ -18,6 +18,7 @@ import { SIGNUP_URL } from 'shared/constants'; import SteemLogo from 'app/components/elements/SteemLogo'; import normalizeProfile from 'app/utils/NormalizeProfile'; import Announcement from 'app/components/elements/Announcement'; +import { GptUtils } from 'app/utils/GptUtils'; import GptAd from 'app/components/elements/GptAd'; class Header extends React.Component { @@ -283,7 +284,13 @@ class Header extends React.Component { )} {/* If announcement is shown, ad will not render unless it's in a parent div! */}
- +