diff --git a/src/__tests__/pages/index.test.js b/src/__tests__/pages/index.test.js
index abd13256..a6a2b4f3 100644
--- a/src/__tests__/pages/index.test.js
+++ b/src/__tests__/pages/index.test.js
@@ -28,10 +28,7 @@ import useData from 'src/utils/hooks/useData'
import getMockAuthUser from 'src/utils/testHelpers/getMockAuthUser'
import LogTabMutation from 'src/utils/mutations/LogTabMutation'
import { v4 as uuid } from 'uuid'
-import LogUserRevenueMutation from 'src/utils/mutations/LogUserRevenueMutation'
-import { AdComponent } from 'tab-ads'
import { isClientSide } from 'src/utils/ssr'
-import { getAdUnits } from 'src/utils/adHelpers'
import { accountCreated, newTabView } from 'src/utils/events'
import MissionHubButton from 'src/components/MissionHubButton'
import InviteFriendsIconContainer from 'src/components/InviteFriendsIconContainer'
@@ -115,30 +112,6 @@ jest.mock('src/utils/hooks/useBrowserName')
jest.mock('src/utils/browserSupport')
jest.mock('src/utils/localStorageFeaturesManager')
-const setUpAds = () => {
- isClientSide.mockReturnValue(true)
- getAdUnits.mockReturnValue({
- leaderboard: {
- // The long leaderboard ad.
- adId: 'div-gpt-ad-1464385677836-0',
- adUnitId: '/43865596/HBTL',
- sizes: [[728, 90]],
- },
- rectangleAdPrimary: {
- // The primary rectangle ad (bottom-right).
- adId: 'div-gpt-ad-1464385742501-0',
- adUnitId: '/43865596/HBTR',
- sizes: [[300, 250]],
- },
- rectangleAdSecondary: {
- // The second rectangle ad (right side, above the first).
- adId: 'div-gpt-ad-1539903223131-0',
- adUnitId: '/43865596/HBTR2',
- sizes: [[300, 250]],
- },
- })
-}
-
const getMockProps = () => ({
data: {
app: {},
@@ -676,153 +649,6 @@ describe('index.js', () => {
expect(accountCreated).not.toHaveBeenCalled()
})
- it('calls LogUserRevenueMutation for each Ad when the onAdDisplayed prop is invoked', () => {
- setUpAds()
- const IndexPage = require('src/pages/index').default
- const wrapper = mount()
- const firstAd = wrapper.find(AdComponent).at(0)
- const secondAd = wrapper.find(AdComponent).at(1)
- const thirdAd = wrapper.find(AdComponent).at(2)
-
- const mockDisplayedAdInfo = {
- adId: 'first-ad-here',
- revenue: 0.0123,
- encodedRevenue: 'encoded-first-ad',
- GAMAdvertiserId: 1111,
- GAMAdUnitId: '/12345/SomeAdUnit',
- adSize: '728x90',
- }
-
- // Call each Ad's onAdDisplayed with a mock ad info.
- firstAd.prop('onAdDisplayed')(mockDisplayedAdInfo)
- secondAd.prop('onAdDisplayed')({
- ...mockDisplayedAdInfo,
- adId: 'second-ad-here',
- revenue: 0.082,
- encodedRevenue: 'encoded-second-ad',
- GAMAdvertiserId: 2222,
- GAMAdUnitId: '/12345/SecondAdThing',
- adSize: '300x250',
- })
- thirdAd.prop('onAdDisplayed')({
- ...mockDisplayedAdInfo,
- adId: 'third-ad-here',
- revenue: 0.0001472,
- encodedRevenue: 'encoded-third-ad',
- GAMAdvertiserId: 3333,
- GAMAdUnitId: '/12345/ThirdAdHere',
- adSize: '300x250',
- })
-
- expect(LogUserRevenueMutation.mock.calls[0][0]).toEqual({
- userId: 'asdf',
- revenue: 0.0123,
- encodedRevenue: {
- encodingType: 'AMAZON_CPM',
- encodedValue: 'encoded-first-ad',
- },
- dfpAdvertiserId: '1111',
- adSize: '728x90',
- aggregationOperation: 'MAX',
- tabId: 'some-uuid',
- adUnitCode: '/12345/SomeAdUnit',
- })
- expect(LogUserRevenueMutation.mock.calls[1][0]).toEqual({
- userId: 'asdf',
- revenue: 0.082,
- encodedRevenue: {
- encodingType: 'AMAZON_CPM',
- encodedValue: 'encoded-second-ad',
- },
- dfpAdvertiserId: '2222',
- adSize: '300x250',
- aggregationOperation: 'MAX',
- tabId: 'some-uuid',
- adUnitCode: '/12345/SecondAdThing',
- })
- expect(LogUserRevenueMutation.mock.calls[2][0]).toEqual({
- userId: 'asdf',
- revenue: 0.0001472,
- encodedRevenue: {
- encodingType: 'AMAZON_CPM',
- encodedValue: 'encoded-third-ad',
- },
- dfpAdvertiserId: '3333',
- adSize: '300x250',
- aggregationOperation: 'MAX',
- tabId: 'some-uuid',
- adUnitCode: '/12345/ThirdAdHere',
- })
- })
-
- it('does not call LogUserRevenueMutation when the ad info is null', () => {
- setUpAds()
- const IndexPage = require('src/pages/index').default
- const wrapper = mount()
- const firstAd = wrapper.find(AdComponent).at(0)
- const secondAd = wrapper.find(AdComponent).at(1)
-
- const mockDisplayedAdInfo = {
- adId: 'first-ad-here',
- revenue: 0.0123,
- encodedRevenue: 'encoded-first-ad',
- GAMAdvertiserId: 1111,
- GAMAdUnitId: '/12345/SomeAdUnit',
- adSize: '728x90',
- }
-
- // Call each Ad's onAdDisplayed with a mock ad info.
- firstAd.prop('onAdDisplayed')(mockDisplayedAdInfo)
- secondAd.prop('onAdDisplayed')(null) // no ad
-
- expect(LogUserRevenueMutation).toHaveBeenCalledTimes(1)
- expect(LogUserRevenueMutation.mock.calls[0][0]).toEqual({
- userId: 'asdf',
- revenue: 0.0123,
- encodedRevenue: {
- encodingType: 'AMAZON_CPM',
- encodedValue: 'encoded-first-ad',
- },
- dfpAdvertiserId: '1111',
- adSize: '728x90',
- aggregationOperation: 'MAX',
- tabId: 'some-uuid',
- adUnitCode: '/12345/SomeAdUnit',
- })
- })
-
- it('does not include encodedRevenue in the LogUserRevenueMutation when the encodedRevenue value is nil', () => {
- setUpAds()
- const IndexPage = require('src/pages/index').default
- const wrapper = mount()
- const firstAd = wrapper.find(AdComponent).at(0)
-
- const mockDisplayedAdInfo = {
- adId: 'first-ad-here',
- revenue: 0.0123,
- encodedRevenue: null, // no encodedRevenue
- GAMAdvertiserId: 1111,
- GAMAdUnitId: '/12345/SomeAdUnit',
- adSize: '728x90',
- }
-
- // Call each Ad's onAdDisplayed with a mock ad info.
- firstAd.prop('onAdDisplayed')(mockDisplayedAdInfo)
-
- expect(LogUserRevenueMutation).toHaveBeenCalledTimes(1)
- expect(LogUserRevenueMutation.mock.calls[0][0]).toEqual({
- userId: 'asdf',
- revenue: 0.0123,
-
- // no encodedRevenue value
- dfpAdvertiserId: '1111',
- adSize: '728x90',
- aggregationOperation: null,
- tabId: 'some-uuid',
- adUnitCode: '/12345/SomeAdUnit',
- })
- })
-
it('shows the intro flow if a user has not completed it', () => {
const defaultMockProps = getMockProps()
const mockProps = {
diff --git a/src/pages/index.js b/src/pages/index.js
index 810c01ba..23d732a2 100644
--- a/src/pages/index.js
+++ b/src/pages/index.js
@@ -2,11 +2,9 @@
import React, { useCallback, useEffect, useState } from 'react'
import PropTypes from 'prop-types'
import { flowRight } from 'lodash/util'
-import { isNil } from 'lodash/lang'
import clsx from 'clsx'
import dayjs from 'dayjs'
import { graphql } from 'react-relay'
-import { AdComponent } from 'tab-ads'
import { v4 as uuid } from 'uuid'
import { get } from 'lodash/object'
import {
@@ -52,9 +50,8 @@ import localStorageMgr from 'src/utils/localstorage-mgr'
import LogTabMutation from 'src/utils/mutations/LogTabMutation'
import UpdateImpactMutation from 'src/utils/mutations/UpdateImpactMutation'
-import LogUserRevenueMutation from 'src/utils/mutations/LogUserRevenueMutation'
import SetHasViewedIntroFlowMutation from 'src/utils/mutations/SetHasViewedIntroFlowMutation'
-import { getAdUnits, incrementTabsOpenedToday } from 'src/utils/adHelpers'
+import { incrementTabsOpenedToday } from 'src/utils/adHelpers'
import { isClientSide } from 'src/utils/ssr'
import { aboutURL, accountURL, achievementsURL } from 'src/utils/urls'
import {
@@ -63,7 +60,6 @@ import {
showDevelopmentOnlyMissionsFeature,
showInternalOnly,
} from 'src/utils/featureFlags'
-import logger from 'src/utils/logger'
import FullPageLoader from 'src/components/FullPageLoader'
import useData from 'src/utils/hooks/useData'
import {
@@ -317,48 +313,6 @@ const useStyles = makeStyles((theme) => ({
},
}))
-// if (isClientSide()) {
-// // Load ads immediately on the client side when we parse
-// // this file rather than waiting for component mount.
-// const loadAds = () => {
-// try {
-// const setGAMDevKey = isGAMDevEnvironment()
-
-// fetchAds({
-// adUnits: Object.values(getAdUnits()),
-// pageLevelKeyValues: {
-// v4: 'true',
-// causeId: localStorageMgr.getCauseForGAM(),
-// ...(setGAMDevKey && { dev: 'true' }),
-// },
-// auctionTimeout: 1000,
-// bidderTimeout: 700,
-// consent: {
-// enabled: true,
-
-// // Time to wait for the consent management platform (CMP) to respond.
-// // If the CMP does not respond in this time, ad auctions may be cancelled.
-// // The tab-cmp package aims to make the CMP respond much more quickly
-// // than this after the user's first page load.
-// timeout: 500,
-// },
-// publisher: {
-// pageUrl: getCurrentURL(),
-// },
-// logLevel: 'error',
-// onError: (e) => {
-// logger.error(e)
-// },
-// disableAds: !areAdsEnabled(),
-// useMockAds: showMockAds(),
-// })
-// } catch (e) {
-// logger.error(e)
-// }
-// }
-// loadAds()
-// }
-
const getRelayQuery = async ({ AuthUser }) => {
// If the user is not authenticated, don't try to fetch data
// for this page. We won't render the page until data exists.
@@ -485,21 +439,6 @@ const Index = ({ data: fallbackData, userAgent }) => {
}
}, [])
- // Determine which ad units we'll show only once, on mount,
- // because the ads have already been fetched and won't change.
- const [adUnits, setAdUnits] = useState([])
- useEffect(() => {
- setAdUnits(getAdUnits())
- }, [])
-
- // Only render ads if we are on the client side.
- const [shouldRenderAds, setShouldRenderAds] = useState(false)
- useEffect(() => {
- if (isClientSide()) {
- setShouldRenderAds(true)
- }
- }, [])
-
const { app, user, userImpact } = data || {}
const {
@@ -781,63 +720,6 @@ const Index = ({ data: fallbackData, userAgent }) => {
// Determine if we should show mission content.
const missionsFeatureEnabled = showDevelopmentOnlyMissionsFeature(email)
- // Data to provide the onAdDisplayed callback
- const adContext = {
- user,
- tabId,
- }
-
- /*
- * A handler for AdComponents' onAdDisplayed callbacks, which receives
- * info about the displayed ad.
- * @param {Object|null} displayedAdInfo - A DisplayedAdInfo from tab-ads. See:
- * https://github.com/gladly-team/tab-ads/blob/master/src/utils/DisplayedAdInfo.js
- * @param {Object} context - Additional info to help with revenue logging
- * @param {Object} context.user - The user object
- * @param {String} context.user.id - The user ID
- * @param {String} context.tabId - A UUID for this page load
- * @return {undefined}
- */
- const onAdDisplayed = (displayedAdInfo, context) => {
- // No ad was shown.
- if (!displayedAdInfo) {
- return
- }
-
- const { revenue, encodedRevenue, GAMAdvertiserId, GAMAdUnitId, adSize } =
- displayedAdInfo
-
- // Log the revenue from the ad.
- LogUserRevenueMutation({
- userId: context.user.id,
- revenue,
- ...(encodedRevenue && {
- encodedRevenue: {
- encodingType: 'AMAZON_CPM',
- encodedValue: encodedRevenue,
- },
- }),
- dfpAdvertiserId: GAMAdvertiserId.toString(),
- adSize,
-
- // Only send aggregationOperation value if we have more than one
- // revenue value
- aggregationOperation:
- !isNil(revenue) && !isNil(encodedRevenue) ? 'MAX' : null,
- tabId: context.tabId,
- adUnitCode: GAMAdUnitId,
- })
- }
-
- /*
- * Log any errors the occur in the Ad components.
- * @param {Object} e - The error
- * @return {undefined}
- */
- const onAdError = (e) => {
- logger.error(e)
- }
-
const onCompletedOnboarding = async () => {
await SetHasViewedIntroFlowMutation({ enabled: true, userId: userGlobalId })
setJustFinishedIntroFlow(true)
@@ -1168,51 +1050,35 @@ const Index = ({ data: fallbackData, userAgent }) => {
- {adUnits.rectangleAdSecondary && shouldRenderAds ? (
-
{
- onAdDisplayed(displayedAdInfo, adContext)
- }}
- onError={onAdError}
- style={{
- display: 'flex',
- minWidth: 300,
- overflow: 'visible',
- }}
- />
- ) : null}
- {adUnits.rectangleAdPrimary && shouldRenderAds ? (
- {
- onAdDisplayed(displayedAdInfo, adContext)
- }}
- onError={onAdError}
- style={{
- display: 'flex',
- minWidth: 300,
- overflow: 'visible',
- marginTop: 10,
- }}
- />
- ) : null}
+
+
+
+
+
+
- {adUnits.leaderboard && shouldRenderAds ? (
-
-
{
- onAdDisplayed(displayedAdInfo, adContext)
- }}
- onError={onAdError}
- style={{
- overflow: 'visible',
- minWidth: 728,
- }}
- />
-
- ) : null}
{(impactType === CAUSE_IMPACT_TYPES.group ||