@contentpass/react-native-contentpass 0.2.5 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/README.md +19 -3
  2. package/docs/CODE_OF_CONDUCT.md +133 -0
  3. package/docs/CONTRIBUTING.md +137 -0
  4. package/docs/SOURCEPOINT_SDK_INTEGRATION.md +112 -0
  5. package/docs/assets/sourcepoint-button-config.png +0 -0
  6. package/docs/assets/sourcepoint-property-example.png +0 -0
  7. package/docs/sourcepoint-patches/@sourcepoint-react-native-cmp-npm-0.3.0-2434c31dc9.patch +78 -0
  8. package/docs/sourcepoint-patches/@sourcepoint-react-native-cmp-patch-34fca36663.patch +13 -0
  9. package/lib/commonjs/Contentpass.js +97 -6
  10. package/lib/commonjs/Contentpass.js.map +1 -1
  11. package/lib/commonjs/OidcAuthStateStorage.js +8 -1
  12. package/lib/commonjs/OidcAuthStateStorage.js.map +1 -1
  13. package/lib/commonjs/{utils → contentpassTokenUtils}/fetchContentpassToken.js +3 -0
  14. package/lib/commonjs/contentpassTokenUtils/fetchContentpassToken.js.map +1 -0
  15. package/lib/commonjs/contentpassTokenUtils/parseContentpassToken.js.map +1 -0
  16. package/lib/commonjs/contentpassTokenUtils/validateSubscription.js.map +1 -0
  17. package/lib/commonjs/countImpressionUtils/sendPageViewEvent.js +24 -0
  18. package/lib/commonjs/countImpressionUtils/sendPageViewEvent.js.map +1 -0
  19. package/lib/commonjs/countImpressionUtils/sendStats.js +20 -0
  20. package/lib/commonjs/countImpressionUtils/sendStats.js.map +1 -0
  21. package/lib/commonjs/logger.js +27 -0
  22. package/lib/commonjs/logger.js.map +1 -0
  23. package/lib/commonjs/sentryIntegration.js +5 -0
  24. package/lib/commonjs/sentryIntegration.js.map +1 -1
  25. package/lib/module/Contentpass.js +95 -6
  26. package/lib/module/Contentpass.js.map +1 -1
  27. package/lib/module/OidcAuthStateStorage.js +8 -1
  28. package/lib/module/OidcAuthStateStorage.js.map +1 -1
  29. package/lib/module/{utils → contentpassTokenUtils}/fetchContentpassToken.js +3 -0
  30. package/lib/module/contentpassTokenUtils/fetchContentpassToken.js.map +1 -0
  31. package/lib/module/contentpassTokenUtils/parseContentpassToken.js.map +1 -0
  32. package/lib/module/contentpassTokenUtils/validateSubscription.js.map +1 -0
  33. package/lib/module/countImpressionUtils/sendPageViewEvent.js +20 -0
  34. package/lib/module/countImpressionUtils/sendPageViewEvent.js.map +1 -0
  35. package/lib/module/countImpressionUtils/sendStats.js +16 -0
  36. package/lib/module/countImpressionUtils/sendStats.js.map +1 -0
  37. package/lib/module/logger.js +22 -0
  38. package/lib/module/logger.js.map +1 -0
  39. package/lib/module/sentryIntegration.js +4 -0
  40. package/lib/module/sentryIntegration.js.map +1 -1
  41. package/lib/typescript/commonjs/src/Contentpass.d.ts +15 -1
  42. package/lib/typescript/commonjs/src/Contentpass.d.ts.map +1 -1
  43. package/lib/typescript/commonjs/src/OidcAuthStateStorage.d.ts.map +1 -1
  44. package/lib/typescript/commonjs/src/contentpassTokenUtils/fetchContentpassToken.d.ts.map +1 -0
  45. package/lib/typescript/commonjs/src/contentpassTokenUtils/parseContentpassToken.d.ts.map +1 -0
  46. package/lib/typescript/commonjs/src/contentpassTokenUtils/validateSubscription.d.ts.map +1 -0
  47. package/lib/typescript/commonjs/src/countImpressionUtils/sendPageViewEvent.d.ts +8 -0
  48. package/lib/typescript/commonjs/src/countImpressionUtils/sendPageViewEvent.d.ts.map +1 -0
  49. package/lib/typescript/commonjs/src/countImpressionUtils/sendStats.d.ts +10 -0
  50. package/lib/typescript/commonjs/src/countImpressionUtils/sendStats.d.ts.map +1 -0
  51. package/lib/typescript/commonjs/src/logger.d.ts +8 -0
  52. package/lib/typescript/commonjs/src/logger.d.ts.map +1 -0
  53. package/lib/typescript/commonjs/src/sentryIntegration.d.ts.map +1 -1
  54. package/lib/typescript/commonjs/src/types/ContentpassConfig.d.ts +5 -0
  55. package/lib/typescript/commonjs/src/types/ContentpassConfig.d.ts.map +1 -1
  56. package/lib/typescript/module/src/Contentpass.d.ts +15 -1
  57. package/lib/typescript/module/src/Contentpass.d.ts.map +1 -1
  58. package/lib/typescript/module/src/OidcAuthStateStorage.d.ts.map +1 -1
  59. package/lib/typescript/module/src/contentpassTokenUtils/fetchContentpassToken.d.ts.map +1 -0
  60. package/lib/typescript/module/src/contentpassTokenUtils/parseContentpassToken.d.ts.map +1 -0
  61. package/lib/typescript/module/src/contentpassTokenUtils/validateSubscription.d.ts.map +1 -0
  62. package/lib/typescript/module/src/countImpressionUtils/sendPageViewEvent.d.ts +8 -0
  63. package/lib/typescript/module/src/countImpressionUtils/sendPageViewEvent.d.ts.map +1 -0
  64. package/lib/typescript/module/src/countImpressionUtils/sendStats.d.ts +10 -0
  65. package/lib/typescript/module/src/countImpressionUtils/sendStats.d.ts.map +1 -0
  66. package/lib/typescript/module/src/logger.d.ts +8 -0
  67. package/lib/typescript/module/src/logger.d.ts.map +1 -0
  68. package/lib/typescript/module/src/sentryIntegration.d.ts.map +1 -1
  69. package/lib/typescript/module/src/types/ContentpassConfig.d.ts +5 -0
  70. package/lib/typescript/module/src/types/ContentpassConfig.d.ts.map +1 -1
  71. package/package.json +5 -2
  72. package/lib/commonjs/utils/fetchContentpassToken.js.map +0 -1
  73. package/lib/commonjs/utils/parseContentpassToken.js.map +0 -1
  74. package/lib/commonjs/utils/validateSubscription.js.map +0 -1
  75. package/lib/module/utils/fetchContentpassToken.js.map +0 -1
  76. package/lib/module/utils/parseContentpassToken.js.map +0 -1
  77. package/lib/module/utils/validateSubscription.js.map +0 -1
  78. package/lib/typescript/commonjs/src/utils/fetchContentpassToken.d.ts.map +0 -1
  79. package/lib/typescript/commonjs/src/utils/parseContentpassToken.d.ts.map +0 -1
  80. package/lib/typescript/commonjs/src/utils/validateSubscription.d.ts.map +0 -1
  81. package/lib/typescript/module/src/utils/fetchContentpassToken.d.ts.map +0 -1
  82. package/lib/typescript/module/src/utils/parseContentpassToken.d.ts.map +0 -1
  83. package/lib/typescript/module/src/utils/validateSubscription.d.ts.map +0 -1
  84. /package/lib/commonjs/{utils → contentpassTokenUtils}/parseContentpassToken.js +0 -0
  85. /package/lib/commonjs/{utils → contentpassTokenUtils}/validateSubscription.js +0 -0
  86. /package/lib/module/{utils → contentpassTokenUtils}/parseContentpassToken.js +0 -0
  87. /package/lib/module/{utils → contentpassTokenUtils}/validateSubscription.js +0 -0
  88. /package/lib/typescript/commonjs/src/{utils → contentpassTokenUtils}/fetchContentpassToken.d.ts +0 -0
  89. /package/lib/typescript/commonjs/src/{utils → contentpassTokenUtils}/parseContentpassToken.d.ts +0 -0
  90. /package/lib/typescript/commonjs/src/{utils → contentpassTokenUtils}/validateSubscription.d.ts +0 -0
  91. /package/lib/typescript/module/src/{utils → contentpassTokenUtils}/fetchContentpassToken.d.ts +0 -0
  92. /package/lib/typescript/module/src/{utils → contentpassTokenUtils}/parseContentpassToken.d.ts +0 -0
  93. /package/lib/typescript/module/src/{utils → contentpassTokenUtils}/validateSubscription.d.ts +0 -0
package/README.md CHANGED
@@ -37,9 +37,12 @@ npx expo prebuild
37
37
 
38
38
  ### Initialization
39
39
  Wrap your app's root component with ContentpassSdkProvider. The provider requires a configuration object (contentpassConfig) with the following properties:
40
- - `propertyId` - Your unique property ID
40
+ - `propertyId` - Your unique property ID (ask Contentpass team for details)
41
+ - `planId` - The ID of the plan you want to check the user's subscription status against (ask Contentpass team for details)
41
42
  - `issuer` - The OAuth 2.0 server URL (e.g. `https://my.contentpass.net`)
42
43
  - `redirectUrl` - the redirect URL of your app to which the OAuth2 server will redirect after the authentication
44
+ - `samplingRate` - Optional: The rate at which the SDK will send impression events for unauthenticated users. Default is 0.05 (5%)
45
+ - `logLevel` - Optional: The log level for the SDK. By default logger is disabled. Possible values are 'info', 'warn', 'error' and 'debug'
43
46
 
44
47
 
45
48
  ```jsx
@@ -47,9 +50,12 @@ import React from 'react';
47
50
  import { ContentpassSdkProvider } from '@contentpass/react-native-contentpass';
48
51
 
49
52
  const contentpassConfig = {
50
- propertyId: 'your-property-id',
53
+ propertyId: 'property-id',
54
+ planId: 'plan-id',
51
55
  issuer: 'https://my.contentpass.net',
52
56
  redirectUrl: 'com.yourapp://oauthredirect',
57
+ samplingRate: 0.1,
58
+ logLevel: 'info'
53
59
  };
54
60
 
55
61
  const App = () => {
@@ -70,6 +76,10 @@ The SDK exposes the following methods through the `useContentpassSdk` hook:
70
76
  Initiates the OAuth 2.0 authentication process via a modal interface. It validates the user’s active Contentpass subscriptions
71
77
  upon successful authentication.
72
78
 
79
+ ### countImpression
80
+ Tracks and increments the impression count for the current user. This method should be invoked whenever a user views a
81
+ piece of content. It applies to all users, whether authenticated or unauthenticated.
82
+
73
83
  ### registerObserver
74
84
  Registers a callback function to listen for changes in the user’s authentication and subscription status. The observer function
75
85
  receives a state object describing the current status (see the exported [ContentpassState](./src/types/ContentpassState.ts) type).
@@ -94,6 +104,7 @@ import { Button, View } from 'react-native';
94
104
  const YourApp = () => {
95
105
  const {
96
106
  authenticate,
107
+ countImpression,
97
108
  registerObserver,
98
109
  unregisterObserver,
99
110
  logout,
@@ -115,15 +126,20 @@ const YourApp = () => {
115
126
  return (
116
127
  <View>
117
128
  <Button onPress={authenticate} title={'Authenticate'} />
129
+ <Button onPress={countImpression} title={'Count Impression'} />
118
130
  </View>
119
131
  );
120
132
  };
121
133
  ```
122
134
 
135
+ ## Integration with Sourcepoint SDK
136
+
137
+ See the [Sourcepoint SDK documentation](docs/SOURCEPOINT_SDK_INTEGRATION.md) for information on integrating the Contentpass SDK with the Sourcepoint SDK.
123
138
 
124
139
  ## Contributing
125
140
 
126
- See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
141
+ See the [contributing guide](docs/CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
142
+
127
143
 
128
144
  ## License
129
145
 
@@ -0,0 +1,133 @@
1
+
2
+ # Contributor Covenant Code of Conduct
3
+
4
+ ## Our Pledge
5
+
6
+ We as members, contributors, and leaders pledge to make participation in our
7
+ community a harassment-free experience for everyone, regardless of age, body
8
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
9
+ identity and expression, level of experience, education, socio-economic status,
10
+ nationality, personal appearance, race, caste, color, religion, or sexual
11
+ identity and orientation.
12
+
13
+ We pledge to act and interact in ways that contribute to an open, welcoming,
14
+ diverse, inclusive, and healthy community.
15
+
16
+ ## Our Standards
17
+
18
+ Examples of behavior that contributes to a positive environment for our
19
+ community include:
20
+
21
+ * Demonstrating empathy and kindness toward other people
22
+ * Being respectful of differing opinions, viewpoints, and experiences
23
+ * Giving and gracefully accepting constructive feedback
24
+ * Accepting responsibility and apologizing to those affected by our mistakes,
25
+ and learning from the experience
26
+ * Focusing on what is best not just for us as individuals, but for the overall
27
+ community
28
+
29
+ Examples of unacceptable behavior include:
30
+
31
+ * The use of sexualized language or imagery, and sexual attention or advances of
32
+ any kind
33
+ * Trolling, insulting or derogatory comments, and personal or political attacks
34
+ * Public or private harassment
35
+ * Publishing others' private information, such as a physical or email address,
36
+ without their explicit permission
37
+ * Other conduct which could reasonably be considered inappropriate in a
38
+ professional setting
39
+
40
+ ## Enforcement Responsibilities
41
+
42
+ Community leaders are responsible for clarifying and enforcing our standards of
43
+ acceptable behavior and will take appropriate and fair corrective action in
44
+ response to any behavior that they deem inappropriate, threatening, offensive,
45
+ or harmful.
46
+
47
+ Community leaders have the right and responsibility to remove, edit, or reject
48
+ comments, commits, code, wiki edits, issues, and other contributions that are
49
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
50
+ decisions when appropriate.
51
+
52
+ ## Scope
53
+
54
+ This Code of Conduct applies within all community spaces, and also applies when
55
+ an individual is officially representing the community in public spaces.
56
+ Examples of representing our community include using an official e-mail address,
57
+ posting via an official social media account, or acting as an appointed
58
+ representative at an online or offline event.
59
+
60
+ ## Enforcement
61
+
62
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
63
+ reported to the community leaders responsible for enforcement at
64
+ [INSERT CONTACT METHOD].
65
+ All complaints will be reviewed and investigated promptly and fairly.
66
+
67
+ All community leaders are obligated to respect the privacy and security of the
68
+ reporter of any incident.
69
+
70
+ ## Enforcement Guidelines
71
+
72
+ Community leaders will follow these Community Impact Guidelines in determining
73
+ the consequences for any action they deem in violation of this Code of Conduct:
74
+
75
+ ### 1. Correction
76
+
77
+ **Community Impact**: Use of inappropriate language or other behavior deemed
78
+ unprofessional or unwelcome in the community.
79
+
80
+ **Consequence**: A private, written warning from community leaders, providing
81
+ clarity around the nature of the violation and an explanation of why the
82
+ behavior was inappropriate. A public apology may be requested.
83
+
84
+ ### 2. Warning
85
+
86
+ **Community Impact**: A violation through a single incident or series of
87
+ actions.
88
+
89
+ **Consequence**: A warning with consequences for continued behavior. No
90
+ interaction with the people involved, including unsolicited interaction with
91
+ those enforcing the Code of Conduct, for a specified period of time. This
92
+ includes avoiding interactions in community spaces as well as external channels
93
+ like social media. Violating these terms may lead to a temporary or permanent
94
+ ban.
95
+
96
+ ### 3. Temporary Ban
97
+
98
+ **Community Impact**: A serious violation of community standards, including
99
+ sustained inappropriate behavior.
100
+
101
+ **Consequence**: A temporary ban from any sort of interaction or public
102
+ communication with the community for a specified period of time. No public or
103
+ private interaction with the people involved, including unsolicited interaction
104
+ with those enforcing the Code of Conduct, is allowed during this period.
105
+ Violating these terms may lead to a permanent ban.
106
+
107
+ ### 4. Permanent Ban
108
+
109
+ **Community Impact**: Demonstrating a pattern of violation of community
110
+ standards, including sustained inappropriate behavior, harassment of an
111
+ individual, or aggression toward or disparagement of classes of individuals.
112
+
113
+ **Consequence**: A permanent ban from any sort of public interaction within the
114
+ community.
115
+
116
+ ## Attribution
117
+
118
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
119
+ version 2.1, available at
120
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
121
+
122
+ Community Impact Guidelines were inspired by
123
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
124
+
125
+ For answers to common questions about this code of conduct, see the FAQ at
126
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
127
+ [https://www.contributor-covenant.org/translations][translations].
128
+
129
+ [homepage]: https://www.contributor-covenant.org
130
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
131
+ [Mozilla CoC]: https://github.com/mozilla/diversity
132
+ [FAQ]: https://www.contributor-covenant.org/faq
133
+ [translations]: https://www.contributor-covenant.org/translations
@@ -0,0 +1,137 @@
1
+ # Contributing
2
+
3
+ Contributions are always welcome, no matter how large or small!
4
+
5
+ We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. Before contributing, please read the [code of conduct](./CODE_OF_CONDUCT.md).
6
+
7
+ ## Development workflow
8
+
9
+ This project is a monorepo managed using [Yarn workspaces](https://yarnpkg.com/features/workspaces). It contains the following packages:
10
+
11
+ - The library package in the root directory.
12
+ - An example app in the `example/` directory.
13
+ - An expo example app in the `expoExample/` directory.
14
+ - A shared frontend code for example apps in the `sharedExample/` directory.
15
+
16
+ To get started with the project, run `yarn` in the root directory to install the required dependencies for each package:
17
+
18
+ ```sh
19
+ yarn
20
+ ```
21
+
22
+ > Since the project relies on Yarn workspaces, you cannot use [`npm`](https://github.com/npm/cli) for development.
23
+
24
+ The [example app](/example/) and [expo example app](/expoExample/) demonstrates usage of the library. You need to run it to test any changes you make.
25
+
26
+ It is configured to use the local version of the library, so any changes you make to the library's source code will be reflected in the example apps.
27
+ Changes to the library's JavaScript code will be reflected in the example apps without a rebuild, but native code changes will require a rebuild of the example app.
28
+
29
+ If you want to use Android Studio or XCode to edit the native code, you can open the
30
+ - `example/android`
31
+ - `example/ios`
32
+ - `expoExample/android`
33
+ - `expoExample/ios`
34
+ directories respectively in those editors. To edit the Objective-C or Swift files, open `ios/ContentpassExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > contentpass-react-native-contentpass`.
35
+
36
+ To edit the Java or Kotlin files, open `android` in Android studio and find the source files at `@contentpass/react-native-contentpass` under `Android`.
37
+
38
+ You can use various commands from the root directory to work with the project.
39
+
40
+ To start the packager:
41
+
42
+ ```sh
43
+ yarn example start
44
+ ```
45
+
46
+ OR
47
+
48
+ ```sh
49
+ yarn expo-example start
50
+ ```
51
+
52
+ To run the example app on Android:
53
+
54
+ ```sh
55
+ yarn example android
56
+ ```
57
+
58
+ OR
59
+
60
+ ```sh
61
+ yarn expo-example android
62
+ ```
63
+
64
+ To run the example app on iOS:
65
+
66
+ ```sh
67
+ yarn example ios
68
+ ```
69
+
70
+ OR
71
+
72
+ ```sh
73
+ yarn expo-example ios
74
+ ```
75
+
76
+ Make sure your code passes TypeScript, ESLint and Prettier. Run the following to verify:
77
+
78
+ ```sh
79
+ yarn typecheck
80
+ yarn lint
81
+ yarn prettier:check
82
+ ```
83
+
84
+ To fix formatting errors, run the following:
85
+
86
+ ```sh
87
+ yarn lint --fix
88
+ ```
89
+
90
+ Remember to add tests for your change if possible. Run the unit tests by:
91
+
92
+ ```sh
93
+ yarn test
94
+ ```
95
+
96
+ ### Commit message convention
97
+
98
+ We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages:
99
+
100
+ - `fix`: bug fixes, e.g. fix crash due to deprecated method.
101
+ - `feat`: new features, e.g. add new method to the module.
102
+ - `refactor`: code refactor, e.g. migrate from class components to hooks.
103
+ - `docs`: changes into documentation, e.g. add usage example for the module..
104
+ - `test`: adding or updating tests, e.g. add integration tests using detox.
105
+ - `chore`: tooling changes, e.g. change CI config.
106
+
107
+ Our pre-commit hooks verify that your commit message matches this format when committing.
108
+
109
+ ### Linting and tests
110
+
111
+ [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/)
112
+
113
+ We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing.
114
+
115
+ Our pre-commit hooks verify that the linter and tests pass when committing.
116
+
117
+ ### Publishing to npm
118
+
119
+ We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc.
120
+
121
+ To publish new versions, run the following:
122
+
123
+ ```sh
124
+ yarn release
125
+ ```
126
+
127
+ ### Sending a pull request
128
+
129
+ > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github).
130
+
131
+ When you're sending a pull request:
132
+
133
+ - Prefer small pull requests focused on one change.
134
+ - Verify that linters and tests are passing.
135
+ - Review the documentation to make sure it looks good.
136
+ - Follow the pull request template when opening a pull request.
137
+ - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue.
@@ -0,0 +1,112 @@
1
+ # Integration with Sourcepoint SDK
2
+ The Contentpass SDK can be seamlessly integrated with the Sourcepoint SDK to manage consent. Since the Sourcepoint SDK
3
+ is a separate React Native package, you must install it independently. For detailed guidance, refer to the
4
+ [Sourcepoint SDK documentation](https://github.com/SourcePointUSA/react-native-sourcepoint-cmp).
5
+
6
+
7
+ ## Setting Up Sourcepoint
8
+ To use the Sourcepoint SDK, follow these steps:
9
+
10
+ 1. Create a Sourcepoint Account: Set up a Sourcepoint account and create a property with the type APP.
11
+ 2. Configure the Property, ensure the property includes:
12
+ - Campaigns
13
+ - Partition Sets
14
+ - Scenarios (with the `acps` parameter — see [here](https://docs.contentpass.net/docs/onboarding/cmp/sourcepoint#4-sourcepoint-contentpass-integration) for details)
15
+ - Messages
16
+
17
+ For more information, consult the [Sourcepoint documentation](https://docs.sourcepoint.com/hc/en-us).
18
+
19
+ A newly created property should resemble the following example:
20
+ ![sourcepoint-property-example.png](./assets/sourcepoint-property-example.png)
21
+
22
+ ### Adding a Custom Action to Sourcepoint Messages
23
+ To integrate the Sourcepoint SDK with the Contentpass SDK, you must define a custom action in Sourcepoint Messages:
24
+ 1. Navigate to `Messages` > `GDPR Messages` > `Web / Webview (TCF)`.
25
+ 2. Edit the relevant message and add a custom action to the login button, such as `cp('login')`.
26
+ 3. This custom action will authenticate users through the Contentpass SDK.
27
+
28
+ Example configuration:
29
+ ![sourcepoint-button-config.png](./assets/sourcepoint-button-config.png)
30
+
31
+ ## Code Integration
32
+ After setting up Sourcepoint, install its SDK package. Use the following code to integrate Contentpass and Sourcepoint
33
+ SDKs in your app.
34
+
35
+ ### Important note
36
+ After creating a property in Sourcepoint, you must wait approximately 15 minutes before it becomes available for use
37
+ with the `@sourcepoint/react-native-cmp` package. This delay allows the configuration to propagate.
38
+
39
+ ### Implementation
40
+ Install the Sourcepoint SDK package, then use the following code to integrate the two SDKs in your app:
41
+
42
+ ```jsx
43
+ import { useEffect, useRef, useState } from 'react';
44
+ import { SPConsentManager } from '@sourcepoint/react-native-cmp';
45
+ import { ContentpassStateType, useContentpassSdk } from '@contentpass/react-native-contentpass';
46
+
47
+ const sourcePointConfig = {
48
+ accountId: 'SOURCEPOINT_ACCOUNT_ID',
49
+ propertyId: 'SOURCEPOINT_PROPERTY_ID',
50
+ propertyName: 'SOURCEPOINT_PROPERTY_NAME',
51
+ };
52
+
53
+ const setupSourcepoint = (hasValidSubscription) => {
54
+ const { accountId, propertyName, propertyId } = sourcePointConfig;
55
+ const spConsentManager = new SPConsentManager();
56
+
57
+ spConsentManager.build(accountId, propertyId, propertyName, {
58
+ gdpr: {
59
+ targetingParams: {
60
+ acps: hasValidSubscription ? 'true' : 'false',
61
+ },
62
+ },
63
+ });
64
+
65
+ return spConsentManager;
66
+ };
67
+
68
+ const App = () => {
69
+ const [authResult, setAuthResult] = useState();
70
+ const contentpassSdk = useContentpassSdk();
71
+ const spConsentManager = useRef();
72
+
73
+ useEffect(() => {
74
+ const onContentpassStateChange = (state) => {
75
+ setAuthResult(state);
76
+ };
77
+
78
+ contentpassSdk.registerObserver(onContentpassStateChange);
79
+
80
+ return () => {
81
+ contentpassSdk.unregisterObserver(onContentpassStateChange);
82
+ };
83
+ }, [contentpassSdk]);
84
+
85
+ useEffect(() => {
86
+ // wait for the authResult to be set before setting up Sourcepoint
87
+ if (!authResult || authResult.state === ContentpassStateType.INITIALISING) {
88
+ return;
89
+ }
90
+
91
+ spConsentManager.current = setupSourcepoint(
92
+ authResult.hasValidSubscription || false
93
+ );
94
+
95
+ spConsentManager.current?.onAction((action) => {
96
+ if (action.customActionId === "cp('login')") {
97
+ contentpassSdk.authenticate()
98
+ }
99
+ });
100
+
101
+ spConsentManager.current?.loadMessage();
102
+
103
+ return () => {
104
+ spConsentManager.current?.dispose();
105
+ };
106
+ }, [authResult, contentpassSdk]);
107
+
108
+ return (
109
+ // Your app content
110
+ )
111
+ }
112
+ ```
@@ -0,0 +1,78 @@
1
+ diff --git a/android/src/main/java/com/sourcepoint/reactnativecmp/RNSourcepointCmpModule.kt b/android/src/main/java/com/sourcepoint/reactnativecmp/RNSourcepointCmpModule.kt
2
+ index deb04fb18dbd8adffcb225801ad35b3154a3c7ad..4d372d921cbae6163179435feb9c821e3c37134b 100644
3
+ --- a/android/src/main/java/com/sourcepoint/reactnativecmp/RNSourcepointCmpModule.kt
4
+ +++ b/android/src/main/java/com/sourcepoint/reactnativecmp/RNSourcepointCmpModule.kt
5
+ @@ -119,6 +119,7 @@ class RNSourcepointCmpModule internal constructor(context: ReactApplicationConte
6
+ override fun onAction(view: View, consentAction: ConsentAction): ConsentAction {
7
+ sendEvent(SDKEvent.onAction, createMap().apply {
8
+ putString("actionType", RNSourcepointActionType.from(consentAction.actionType).name)
9
+ + putString("customActionId", consentAction.customActionId ?: "")
10
+ })
11
+ return consentAction
12
+ }
13
+ diff --git a/ios/RNSourcepointCmp.swift b/ios/RNSourcepointCmp.swift
14
+ index 556b56618c847ad8aeaf9cdc680813cc26b732a9..ba7d707232d72fe5038ec05fb6fdb8e27216e4ee 100644
15
+ --- a/ios/RNSourcepointCmp.swift
16
+ +++ b/ios/RNSourcepointCmp.swift
17
+ @@ -69,7 +69,10 @@ extension RNSourcepointCmp: SPDelegate {
18
+ func onAction(_ action: SPAction, from controller: UIViewController) {
19
+ RNSourcepointCmp.shared?.sendEvent(
20
+ withName: "onAction",
21
+ - body: ["actionType": RNSourcepointActionType(from: action.type).rawValue]
22
+ + body: [
23
+ + "actionType": RNSourcepointActionType(from: action.type).rawValue,
24
+ + "customActionId": action.customActionId ?? "",
25
+ + ]
26
+ )
27
+ }
28
+
29
+ diff --git a/lib/typescript/src/index.d.ts b/lib/typescript/src/index.d.ts
30
+ index 1602516717becd5ec0a8e5036ad2d821110af96f..67bb9e5153b7489c5ead4dcd056b502b71bc2a7d 100644
31
+ --- a/lib/typescript/src/index.d.ts
32
+ +++ b/lib/typescript/src/index.d.ts
33
+ @@ -12,6 +12,7 @@ export declare class SPConsentManager implements Spec {
34
+ loadUSNatPrivacyManager(pmId: string): void;
35
+ onAction(callback: (body: {
36
+ actionType: SPActionType;
37
+ + customActionId: string;
38
+ }) => void): void;
39
+ onSPUIReady(callback: () => void): void;
40
+ onSPUIFinished(callback: () => void): void;
41
+ diff --git a/lib/typescript/src/types.d.ts b/lib/typescript/src/types.d.ts
42
+ index a15f7a06c3e0635168987a44a33009ff42bbd31c..a035a72af14f32adf0ff88f959eb8c517ffaea47 100644
43
+ --- a/lib/typescript/src/types.d.ts
44
+ +++ b/lib/typescript/src/types.d.ts
45
+ @@ -86,6 +86,7 @@ export interface Spec extends TurboModule {
46
+ loadUSNatPrivacyManager(pmId: string): void;
47
+ onAction(callback: (body: {
48
+ actionType: SPActionType;
49
+ + customActionId: string;
50
+ }) => void): void;
51
+ onSPUIReady(callback: () => void): void;
52
+ onSPUIFinished(callback: () => void): void;
53
+ diff --git a/src/index.ts b/src/index.ts
54
+ index b3e76b15572c56f1a4e54068b90243d6dd028e18..a03d87fea4a93edb6bf904c99d32b029b840bade 100644
55
+ --- a/src/index.ts
56
+ +++ b/src/index.ts
57
+ @@ -67,7 +67,7 @@ export class SPConsentManager implements Spec {
58
+ RNSourcepointCmp.loadUSNatPrivacyManager(pmId);
59
+ }
60
+
61
+ - onAction(callback: (body: { actionType: SPActionType }) => void): void {
62
+ + onAction(callback: (body: { actionType: SPActionType, customActionId: string }) => void): void {
63
+ this.emitter.removeAllListeners('onAction');
64
+ this.emitter.addListener('onAction', callback);
65
+ }
66
+ diff --git a/src/types.ts b/src/types.ts
67
+ index 26ac3d8162c0534af98e2a20d237856195fe5a10..4257aff5ed128988c7d3fba60545672966162b20 100644
68
+ --- a/src/types.ts
69
+ +++ b/src/types.ts
70
+ @@ -113,7 +113,7 @@ export interface Spec extends TurboModule {
71
+ loadGDPRPrivacyManager(pmId: string): void;
72
+ loadUSNatPrivacyManager(pmId: string): void;
73
+
74
+ - onAction(callback: (body: { actionType: SPActionType }) => void): void;
75
+ + onAction(callback: (body: { actionType: SPActionType, customActionId: string }) => void): void;
76
+ onSPUIReady(callback: () => void): void;
77
+ onSPUIFinished(callback: () => void): void;
78
+ onFinished(callback: () => void): void;
@@ -0,0 +1,13 @@
1
+ diff --git a/android/src/main/java/com/sourcepoint/reactnativecmp/RNSourcepointCmpTypes.kt b/android/src/main/java/com/sourcepoint/reactnativecmp/RNSourcepointCmpTypes.kt
2
+ index bb8c6c37adc3d7980c7e92268b98b9d97ef8de40..3d67b3a3f44743c4542a1966e66e1af3ea93c555 100644
3
+ --- a/android/src/main/java/com/sourcepoint/reactnativecmp/RNSourcepointCmpTypes.kt
4
+ +++ b/android/src/main/java/com/sourcepoint/reactnativecmp/RNSourcepointCmpTypes.kt
5
+ @@ -16,7 +16,7 @@ data class SPCampaign(
6
+ val rawTargetingParam: ReadableMap?,
7
+ val supportLegacyUSPString: Boolean
8
+ ) {
9
+ - val targetingParams = rawTargetingParam?.toHashMap()?.map { TargetingParam(it.key, it.toString()) } ?: emptyList()
10
+ + val targetingParams = rawTargetingParam?.toHashMap()?.map { TargetingParam(it.key, it.value.toString()) } ?: emptyList()
11
+ }
12
+
13
+ data class SPCampaigns(