apps-sdk 1.1.67 → 1.1.68
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.
- package/package.json +1 -1
- package/src/libraries/Facebook.js +65 -1
package/package.json
CHANGED
|
@@ -146,6 +146,70 @@ class Facebook {
|
|
|
146
146
|
getApplicationId() {
|
|
147
147
|
return this.appId;
|
|
148
148
|
}
|
|
149
|
+
|
|
150
|
+
async getCampaignData() {
|
|
151
|
+
if (!this.isInitialized) {
|
|
152
|
+
console.log('Facebook is not initialized');
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
try {
|
|
157
|
+
// Import AppLink from react-native-fbsdk-next
|
|
158
|
+
const { AppLink } = await import('react-native-fbsdk-next');
|
|
159
|
+
|
|
160
|
+
config.DEBUG_MODE && console.log('Fetching deferred app link data from Meta...');
|
|
161
|
+
|
|
162
|
+
// Fetch deferred app link - this returns the URL or null
|
|
163
|
+
const deferredAppLink = await AppLink.fetchDeferredAppLink();
|
|
164
|
+
|
|
165
|
+
if (deferredAppLink) {
|
|
166
|
+
config.DEBUG_MODE && console.log('Deferred app link received:', deferredAppLink);
|
|
167
|
+
|
|
168
|
+
// Parse the URL to extract campaign parameters
|
|
169
|
+
const campaignData = this.parseCampaignUrl(deferredAppLink);
|
|
170
|
+
|
|
171
|
+
config.DEBUG_MODE && console.log('Parsed campaign data:', campaignData);
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
url: deferredAppLink,
|
|
175
|
+
...campaignData
|
|
176
|
+
};
|
|
177
|
+
} else {
|
|
178
|
+
config.DEBUG_MODE && console.log('No deferred app link data available');
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
} catch (error) {
|
|
182
|
+
console.error('Error fetching campaign data from Meta:', error);
|
|
183
|
+
Networking.sendEvent('other', 'facebook_campaign_data_error', { error: error.message });
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
parseCampaignUrl(url) {
|
|
190
|
+
try {
|
|
191
|
+
const urlObj = new URL(url);
|
|
192
|
+
const params = {};
|
|
193
|
+
|
|
194
|
+
// Extract all query parameters
|
|
195
|
+
urlObj.searchParams.forEach((value, key) => {
|
|
196
|
+
params[key] = value;
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
params,
|
|
201
|
+
host: urlObj.host,
|
|
202
|
+
path: urlObj.pathname,
|
|
203
|
+
protocol: urlObj.protocol
|
|
204
|
+
};
|
|
205
|
+
} catch (error) {
|
|
206
|
+
console.error('Error parsing campaign URL:', error);
|
|
207
|
+
return {
|
|
208
|
+
params: {},
|
|
209
|
+
raw_url: url
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
}
|
|
149
213
|
}
|
|
150
214
|
|
|
151
|
-
export default new Facebook();
|
|
215
|
+
export default new Facebook();
|