Skip to content

Commit 1fd06b6

Browse files
committed
docs: add docs about sourcepoint integration
1 parent 5d208d4 commit 1fd06b6

9 files changed

+223
-1
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,12 @@ const YourApp = () => {
123123

124124
## Contributing
125125

126-
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
126+
See the [contributing guide](docs/CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
127+
128+
## Integration with Sourcepoint SDK
129+
130+
See the [Sourcepoint SDK documentation](./docs/SOURCEPOINT.md) for information on integrating the Contentpass SDK with the Sourcepoint SDK.
131+
127132

128133
## License
129134

File renamed without changes.
File renamed without changes.
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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+
For more information, consult the [Sourcepoint documentation](https://docs.sourcepoint.com/hc/en-us).
17+
18+
A newly created property should resemble the following example:
19+
![sourcepoint-property-example.png](./assets/sourcepoint-property-example.png)
20+
21+
### Adding a Custom Action to Sourcepoint Messages
22+
To integrate the Sourcepoint SDK with the Contentpass SDK, you must define a custom action in Sourcepoint Messages:
23+
1. Navigate to `Messages` > `GDPR Messages` > `Web / Webview (TCF)`.
24+
2. Edit the relevant message and add a custom action to the login button, such as `cp('login')`.
25+
3. This custom action will authenticate users through the Contentpass SDK.
26+
27+
Example configuration:
28+
![sourcepoint-button-config.png](./assets/sourcepoint-button-config.png)
29+
30+
## Code Integration
31+
After setting up Sourcepoint, install its SDK package. Use the following code to integrate Contentpass and Sourcepoint
32+
SDKs in your app.
33+
34+
### Important note
35+
After creating a property in Sourcepoint, you must wait approximately 15 minutes before it becomes available for use
36+
with the `@sourcepoint/react-native-cmp package`. This delay allows the configuration to propagate.
37+
38+
### Implementation
39+
Install the Sourcepoint SDK package, then use the following code to integrate the two SDKs in your app:
40+
41+
```jsx
42+
import { useEffect, useRef, useState } from 'react';
43+
import { SPConsentManager } from '@sourcepoint/react-native-cmp';
44+
import { ContentpassStateType, useContentpassSdk } from '@contentpass/react-native-contentpass';
45+
46+
const sourcePointConfig = {
47+
accountId: 'SOURCEPOINT_ACCOUNT_ID',
48+
propertyId: 'SOURCEPOINT_PROPERTY_ID',
49+
propertyName: 'SOURCEPOINT_PROPERTY_NAME',
50+
};
51+
52+
const setupSourcepoint = (hasValidSubscription) => {
53+
const { accountId, propertyName, propertyId } = sourcePointConfig;
54+
const spConsentManager = new SPConsentManager();
55+
56+
spConsentManager.build(accountId, propertyId, propertyName, {
57+
gdpr: {
58+
targetingParams: {
59+
acps: hasValidSubscription ? 'true' : 'false',
60+
},
61+
},
62+
});
63+
64+
return spConsentManager;
65+
};
66+
67+
const App = () => {
68+
const [authResult, setAuthResult] = useState();
69+
const contentpassSdk = useContentpassSdk();
70+
const spConsentManager = useRef();
71+
72+
useEffect(() => {
73+
const onContentpassStateChange = (state) => {
74+
setAuthResult(state);
75+
};
76+
77+
contentpassSdk.registerObserver(onContentpassStateChange);
78+
79+
return () => {
80+
contentpassSdk.unregisterObserver(onContentpassStateChange);
81+
};
82+
}, [contentpassSdk]);
83+
84+
useEffect(() => {
85+
// wait for the authResult to be set before setting up Sourcepoint
86+
if (!authResult || authResult.state === ContentpassStateType.INITIALISING) {
87+
return;
88+
}
89+
90+
spConsentManager.current = setupSourcepoint(
91+
authResult?.hasValidSubscription ?? false
92+
);
93+
94+
spConsentManager.current?.onAction((action) => {
95+
if (action.customActionId === "cp('login')") {
96+
contentpassSdk.authenticate()
97+
}
98+
});
99+
100+
spConsentManager.current?.loadMessage();
101+
102+
return () => {
103+
spConsentManager.current?.dispose();
104+
};
105+
}, [authResult, contentpassSdk]);
106+
107+
return (
108+
// Your app content
109+
)
110+
}
111+
```
112+
113+
## Troubleshooting
114+
While integrating the Contentpass SDK with Sourcepoint SDK (version `0.3.0`), you may encounter known issues. Pull requests
115+
addressing these issues have been submitted in the [Sourcepoint GitHub repository](https://github.com/SourcePointUSA/react-native-sourcepoint-cmp):
116+
- [PR #10](https://github.com/SourcePointUSA/react-native-sourcepoint-cmp/pull/10)
117+
- [PR #11](https://github.com/SourcePointUSA/react-native-sourcepoint-cmp/pull/11)
118+
119+
### Temporary Fixes
120+
If these fixes are not yet available in the latest version of the SDK, you can patch node_modules in your project using
121+
tools like `yarn patch` or similar. The patch files can be found here:
122+
- Patch for [PR #10](https://github.com/SourcePointUSA/react-native-sourcepoint-cmp/pull/10): [@sourcepoint-react-native-cmp-npm-0.3.0-2434c31dc9.patch](./sourcepoint-patches/@sourcepoint-react-native-cmp-npm-0.3.0-2434c31dc9.patch)
123+
- Patch for [PR #11](https://github.com/SourcePointUSA/react-native-sourcepoint-cmp/pull/11): (https://github.com/SourcePointUSA/react-native-sourcepoint-cmp/pull/11): [@sourcepoint-react-native-cmp-patch-34fca36663.patch](./sourcepoint-patches/@sourcepoint-react-native-cmp-patch-34fca36663.patch)
124+
125+
We hope these issues will be resolved in the next release of the Sourcepoint SDK, eliminating the need for manual patches.
204 KB
Loading
23.5 KB
Loading
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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(

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"android",
2424
"ios",
2525
"cpp",
26+
"docs",
2627
"*.podspec",
2728
"!ios/build",
2829
"!android/build",

0 commit comments

Comments
 (0)