Skip to content

Commit e180cdc

Browse files
authored
Merge pull request #23 from contentpass/DOCS-add-docs-about-sourcepoint-integration
docs: add docs about sourcepoint integration
2 parents 5d208d4 + b3d1772 commit e180cdc

9 files changed

+224
-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: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
```
113+
114+
## Troubleshooting
115+
While integrating the Contentpass SDK with Sourcepoint SDK (version `0.3.0`), you may encounter known issues. Pull requests
116+
addressing these issues have been submitted in the [Sourcepoint GitHub repository](https://github.com/SourcePointUSA/react-native-sourcepoint-cmp):
117+
- [PR #10](https://github.com/SourcePointUSA/react-native-sourcepoint-cmp/pull/10)
118+
- [PR #11](https://github.com/SourcePointUSA/react-native-sourcepoint-cmp/pull/11)
119+
120+
### Temporary Fixes
121+
If these fixes are not yet available in the latest version of the SDK, you can patch node_modules in your project using
122+
tools like `yarn patch` or similar. The patch files can be found here:
123+
- 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)
124+
- 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)
125+
126+
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)