-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(monetization): Merge pull request #184 from AlbericoD/feature/ba…
…sic-features feat(monetization): add overwolf ads and subscriptions.
- Loading branch information
Showing
48 changed files
with
483 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from './Feed' | ||
export * from "./Feed"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export const Loading = () => <p>Loading ...</p> | ||
export const Loading = () => <p>Loading ...</p>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from './Loading' | ||
export * from "./Loading"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from './Title' | ||
export * from "./Title"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { useOverwolfAds, type UseOverwolfAds } from "../hooks/useOverwolfAds"; | ||
import "./styles/AdsSlot.css"; | ||
|
||
/** | ||
* Renders an ads slot component. | ||
* @see https://overwolf.github.io/start/monetize-your-app/advertising/working-with-ads#list-of-ad-sizes | ||
* A simple, one Container layout | ||
* Dimensions: 400x300 | ||
* Revenue: Baseline | ||
* Show Video Ads: Yes | ||
* Design Constraints: Minimal | ||
* User Friction: Minimal | ||
* Policies: | ||
* As such, you must also keep in mind the following: | ||
* Do not create Ad experiences that are actively intrusive/clash with the app's basic usage. | ||
* No more than one video Ad container may be placed on a single page at any moment. | ||
* Any manipulation of or interference with the ads integration is not allowed - Bots, auto clickers, constant page reloading, faking impressions, etc. | ||
* Ads may not be placed on dead end/empty screens. This includes: "Thank You" pages, "Login" pages, "Dialogue/Error/Notification", pages Etc | ||
* @test How to test: https://overwolf.github.io/start/test-your-app/how-to-test-your-app#testing-ad-visibility | ||
* @returns The rendered ads slot component. | ||
*/ | ||
export function AdsSlot(size: UseOverwolfAds) { | ||
const { containerRef, isPlaying } = useOverwolfAds(size); | ||
return ( | ||
<div | ||
className='ads-slot' | ||
ref={containerRef} | ||
style={{ | ||
minWidth: size.width, | ||
minHeight: size.height, | ||
maxWidth: size.width, | ||
maxHeight: size.height, | ||
}} | ||
> | ||
{isPlaying ? null : ( | ||
<> | ||
<div className='ads-slot__placeholder' /> | ||
<h1>Ads Slot 400x300</h1> | ||
</> | ||
)} | ||
</div> | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
template/src/features/monetization/components/GetPremium.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { openSubscribeWindow } from "../hooks/useAdRemoval"; | ||
import "./styles/GetPremium.css"; | ||
|
||
export function GetPremium() { | ||
return ( | ||
<div className='get-premium'> | ||
<button className='get-premium__button' onClick={openSubscribeWindow}> | ||
Get Premium: Remove Ads! | ||
</button> | ||
</div> | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
template/src/features/monetization/components/styles/AdsSlot.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.ads-slot { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
width: 100%; | ||
background-color: var(--secondary-color-dark); | ||
padding: 20px; | ||
} | ||
.ads-slot__placeholder { | ||
padding: 10px; | ||
} |
29 changes: 29 additions & 0 deletions
29
template/src/features/monetization/components/styles/GetPremium.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
.get-premium { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100%; | ||
width: 100%; | ||
padding: 20px; | ||
box-sizing: border-box; | ||
} | ||
/* //create a beautiful button */ | ||
.get-premium__button { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
height: 50px; | ||
width: 100%; | ||
background-color: var(--neutral-1); | ||
color: var(--primary-color-text); | ||
font-size: var(--font-size-medium); | ||
font-weight: var(--font-weight); | ||
border-radius: 5px; | ||
cursor: pointer; | ||
transition: background-color 0.2s ease-in-out; | ||
} | ||
|
||
.get-premium__button:hover { | ||
background-color: var(--neutral-2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const OWADS_URL = | ||
"https://content.overwolf.com/libs/ads/latest/owads.min.js"; | ||
export const INJECTED_OWADS_ID = "owads-injected"; | ||
export const SUBSCRIPTION_ID = 123; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { useEffect, useState } from "react"; | ||
import { SUBSCRIPTION_ID } from "../constants"; | ||
import { isDev, sleep } from "lib/utils"; | ||
import { log } from "lib/log"; | ||
|
||
async function openSubscribeWindow() { | ||
if (isDev) { | ||
log( | ||
"dev mode, not opening subscribe window", | ||
"src/features/monetization/hooks/useAdRemoval.ts", | ||
"openSubscribeWindow" | ||
); | ||
return; | ||
} | ||
const UID = await new Promise<string>((resolve, reject) => { | ||
overwolf.extensions.current.getManifest((manifest) => { | ||
if (manifest) { | ||
resolve(manifest.UID); | ||
} else { | ||
reject(null); | ||
} | ||
}); | ||
}); | ||
overwolf.utils.openStore({ | ||
page: "SubscriptionPage" as overwolf.utils.enums.eStorePage.SubscriptionPage, | ||
uid: UID, | ||
}); | ||
} | ||
|
||
const useAdRemoval = () => { | ||
const [isSubscribed, setIsSubscribed] = useState(false); | ||
const [isLoading, setIsLoading] = useState(true); | ||
// Function to handle the subscription change event | ||
|
||
const handleSubscriptionState = () => { | ||
setIsSubscribed(true); | ||
}; | ||
|
||
useEffect(() => { | ||
if (isDev) { | ||
setIsSubscribed(false); | ||
setIsLoading(false); | ||
return; | ||
} | ||
// console.log('plan', subscriptionId) | ||
// Subscribe to the subscription change event | ||
const handleSubscriptionChange = async ( | ||
info: overwolf.profile.subscriptions.SubscriptionChangedEvent | ||
) => { | ||
setIsLoading(true); | ||
console.log("Subscription changed", info); | ||
if (Array.isArray(info?.plans) && info.plans.includes(SUBSCRIPTION_ID)) { | ||
handleSubscriptionState(); | ||
} | ||
await sleep(3_000); | ||
setIsLoading(false); | ||
}; | ||
|
||
overwolf.profile.subscriptions.getActivePlans(async (info) => { | ||
console.log("Active plans", info); | ||
if ( | ||
info.success && | ||
Array.isArray(info?.plans) && | ||
info.plans.includes(SUBSCRIPTION_ID) | ||
) { | ||
handleSubscriptionState(); | ||
} | ||
await sleep(3_000); | ||
setIsLoading(false); | ||
}); | ||
overwolf.profile.subscriptions.onSubscriptionChanged.addListener( | ||
handleSubscriptionChange | ||
); | ||
|
||
// Unsubscribe from the event when the component unmounts | ||
return () => { | ||
overwolf.profile.subscriptions.onSubscriptionChanged.removeListener( | ||
handleSubscriptionChange | ||
); | ||
}; | ||
}, []); | ||
|
||
return { isSubscribed, isLoading }; | ||
}; | ||
|
||
export { useAdRemoval, openSubscribeWindow }; |
Oops, something went wrong.