-
Notifications
You must be signed in to change notification settings - Fork 111
Add experimental trackCustomPaywallImpression API #1660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rickvdl
wants to merge
5
commits into
main
Choose a base branch
from
rickvdl/track-custom-paywall-impression-experimental-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
23fcee2
Add trackCustomPaywallImpression API to React Native
rickvdl 941240b
Add custom paywall demo screen to purchase tester app
rickvdl 0d88f8e
Add unit tests for trackCustomPaywallImpression
rickvdl 4688ba2
Addressed PR feedback
rickvdl 6df2a87
Move TrackCustomPaywallImpressionOptions to top-level exports and add…
rickvdl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
165 changes: 165 additions & 0 deletions
165
examples/purchaseTesterTypescript/app/screens/CustomPaywallScreen.tsx
This file contains hidden or 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,165 @@ | ||
| import React, {useState} from 'react'; | ||
|
|
||
| import { | ||
| SafeAreaView, | ||
| StyleSheet, | ||
| Text, | ||
| TouchableOpacity, | ||
| View, | ||
| } from 'react-native'; | ||
|
|
||
| import Purchases from 'react-native-purchases'; | ||
| import {NativeStackScreenProps} from '@react-navigation/native-stack'; | ||
| import RootStackParamList from '../RootStackParamList'; | ||
|
|
||
| type Props = NativeStackScreenProps<RootStackParamList, 'CustomPaywall'>; | ||
|
|
||
| const CustomPaywallScreen: React.FC<Props> = ({navigation}) => { | ||
| const [status, setStatus] = useState<string | null>(null); | ||
|
|
||
| const trackImpressionNoId = async () => { | ||
| try { | ||
| await Purchases.trackCustomPaywallImpression(); | ||
| setStatus('trackCustomPaywallImpression (no id) succeeded'); | ||
| console.log('[CustomPaywall] Tracked custom paywall impression (no id)'); | ||
| } catch (e) { | ||
| setStatus(`Error: ${e}`); | ||
| } | ||
| }; | ||
|
|
||
| const trackImpressionWithId = async () => { | ||
| try { | ||
| await Purchases.trackCustomPaywallImpression({ | ||
| paywallId: 'my-test-paywall', | ||
| }); | ||
| setStatus('trackCustomPaywallImpression (with id) succeeded'); | ||
| console.log('[CustomPaywall] Tracked custom paywall impression (with id)'); | ||
| } catch (e) { | ||
| setStatus(`Error: ${e}`); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <SafeAreaView style={styles.container}> | ||
| <View style={styles.content}> | ||
| <Text style={styles.title}>Custom Paywall Impression</Text> | ||
| <Text style={styles.description}> | ||
| Use this screen to test tracking custom paywall impressions. | ||
| </Text> | ||
|
|
||
| <TouchableOpacity | ||
| style={styles.button} | ||
| onPress={trackImpressionNoId}> | ||
| <Text style={styles.buttonText}> | ||
| Track custom paywall impression (no id) | ||
| </Text> | ||
| </TouchableOpacity> | ||
|
|
||
| <TouchableOpacity | ||
| style={styles.button} | ||
| onPress={trackImpressionWithId}> | ||
| <Text style={styles.buttonText}> | ||
| Track custom paywall impression (with id) | ||
| </Text> | ||
| </TouchableOpacity> | ||
|
|
||
| {status && ( | ||
| <View | ||
| style={[ | ||
| styles.statusContainer, | ||
| status.startsWith('Error') | ||
| ? styles.errorContainer | ||
| : styles.successContainer, | ||
| ]}> | ||
| <Text | ||
| style={ | ||
| status.startsWith('Error') | ||
| ? styles.errorText | ||
| : styles.successText | ||
| }> | ||
| {status} | ||
| </Text> | ||
| </View> | ||
| )} | ||
|
|
||
| <TouchableOpacity | ||
| style={styles.closeButton} | ||
| onPress={() => navigation.goBack()}> | ||
| <Text style={styles.closeButtonText}>Close</Text> | ||
| </TouchableOpacity> | ||
| </View> | ||
| </SafeAreaView> | ||
| ); | ||
| }; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| container: { | ||
| flex: 1, | ||
| backgroundColor: '#f8f9fa', | ||
| }, | ||
| content: { | ||
| flex: 1, | ||
| padding: 24, | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| }, | ||
| title: { | ||
| fontSize: 28, | ||
| fontWeight: '700', | ||
| marginBottom: 8, | ||
| color: '#212529', | ||
| }, | ||
| description: { | ||
| fontSize: 14, | ||
| color: '#868e96', | ||
| marginBottom: 24, | ||
| textAlign: 'center', | ||
| }, | ||
| button: { | ||
| width: '100%', | ||
| padding: 16, | ||
| backgroundColor: '#1971c2', | ||
| borderRadius: 12, | ||
| alignItems: 'center', | ||
| marginBottom: 12, | ||
| }, | ||
| buttonText: { | ||
| fontSize: 16, | ||
| fontWeight: '600', | ||
| color: '#ffffff', | ||
| }, | ||
| statusContainer: { | ||
| width: '100%', | ||
| padding: 16, | ||
| borderRadius: 8, | ||
| marginTop: 12, | ||
| marginBottom: 12, | ||
| }, | ||
| successContainer: { | ||
| backgroundColor: '#d3f9d8', | ||
| borderColor: '#69db7c', | ||
| borderWidth: 1, | ||
| }, | ||
| errorContainer: { | ||
| backgroundColor: '#ffe3e3', | ||
| borderColor: '#ff8787', | ||
| borderWidth: 1, | ||
| }, | ||
| successText: { | ||
| color: '#2b8a3e', | ||
| fontSize: 14, | ||
| }, | ||
| errorText: { | ||
| color: '#c92a2a', | ||
| fontSize: 14, | ||
| }, | ||
| closeButton: { | ||
| padding: 12, | ||
| }, | ||
| closeButtonText: { | ||
| fontSize: 16, | ||
| color: '#868e96', | ||
| }, | ||
| }); | ||
|
|
||
| export default CustomPaywallScreen; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember we added
isCustomPaywallTrackingAPIAvailablechecker in PHC hereBut it's true that the
trackCustomPaywallImpressionstill requires iOS 15, etc.I wonder how we could use the checker. At a minimum, we should probably log something if the method is not available
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good pint, added the logging here as well :)
I don't think using
isCustomPaywallTrackingAPIAvailableadds much value here since we have to do this@availablecheck anyways. But please LMK if you disagree :)