|
1 | | -import { NativeModules, Platform } from 'react-native' |
| 1 | +import { NativeModules, Platform } from "react-native"; |
2 | 2 |
|
3 | | -const { RNBranch } = NativeModules |
| 3 | +const { RNBranch } = NativeModules; |
4 | 4 |
|
5 | | -import createBranchUniversalObject from './branchUniversalObject' |
6 | | -import BranchEvent from './BranchEvent' |
7 | | -import BranchSubscriber from './BranchSubscriber' |
| 5 | +import createBranchUniversalObject from "./branchUniversalObject"; |
| 6 | +import BranchEvent from "./BranchEvent"; |
| 7 | +import BranchSubscriber from "./BranchSubscriber"; |
8 | 8 |
|
9 | | -const packageFile = require('./../package.json') |
10 | | -export const VERSION = packageFile.version |
| 9 | +const packageFile = require("./../package.json"); |
| 10 | +export const VERSION = packageFile.version; |
11 | 11 |
|
12 | 12 | class Branch { |
13 | 13 | key = null; |
14 | 14 | _checkCachedEvents = true; |
15 | 15 | _debug = false; |
16 | 16 |
|
17 | 17 | constructor(options = {}) { |
18 | | - if (options.debug) this._debug = true |
| 18 | + if (options.debug) this._debug = true; |
19 | 19 |
|
20 | | - console.info('Initializing react-native-branch v. ' + VERSION) |
| 20 | + console.info("Initializing react-native-branch v. " + VERSION); |
21 | 21 | } |
22 | 22 |
|
23 | 23 | subscribe(options) { |
24 | | - if (typeof options === 'function') { |
| 24 | + if (typeof options === "function") { |
25 | 25 | /* |
26 | 26 | * Support for legacy API, passing a single callback function: |
27 | 27 | * branch.subscribe(({params, error, uri}) => { ... }). This is |
28 | 28 | * the same as the onOpenComplete callback. |
29 | 29 | */ |
30 | 30 | options = { |
31 | 31 | onOpenComplete: options, |
32 | | - } |
| 32 | + }; |
33 | 33 | } |
34 | 34 |
|
35 | 35 | /* |
36 | 36 | * You can specify checkCachedEvents in the subscribe options to control |
37 | 37 | * this per subscriber. |
38 | 38 | */ |
39 | | - if (!('checkCachedEvents' in options)) { |
40 | | - options.checkCachedEvents = this._checkCachedEvents |
| 39 | + if (!("checkCachedEvents" in options)) { |
| 40 | + options.checkCachedEvents = this._checkCachedEvents; |
41 | 41 | } |
42 | | - this._checkCachedEvents = false |
| 42 | + this._checkCachedEvents = false; |
43 | 43 |
|
44 | | - const subscriber = new BranchSubscriber(options) |
45 | | - subscriber.subscribe() |
| 44 | + const subscriber = new BranchSubscriber(options); |
| 45 | + subscriber.subscribe(); |
46 | 46 |
|
47 | | - return () => subscriber.unsubscribe() |
| 47 | + return () => subscriber.unsubscribe(); |
48 | 48 | } |
49 | 49 |
|
50 | 50 | skipCachedEvents() { |
51 | 51 | /*** Sets to ignore cached events. ***/ |
52 | | - this._checkCachedEvents = false |
| 52 | + this._checkCachedEvents = false; |
53 | 53 | } |
54 | 54 |
|
55 | 55 | /*** Tracking related methods ***/ |
56 | | - disableTracking = (disable) => RNBranch.disableTracking(disable) |
57 | | - isTrackingDisabled = RNBranch.isTrackingDisabled |
| 56 | + disableTracking = (disable) => RNBranch.disableTracking(disable); |
| 57 | + isTrackingDisabled = RNBranch.isTrackingDisabled; |
58 | 58 |
|
59 | 59 | /*** RNBranch singleton methods ***/ |
60 | | - setDebug = () => { throw 'setDebug() is not supported in the RN SDK. For other solutions, please see https://rnbranch.app.link/setDebug' } |
61 | | - getLatestReferringParams = (synchronous = false) => RNBranch.getLatestReferringParams(synchronous) |
62 | | - getFirstReferringParams = RNBranch.getFirstReferringParams |
63 | | - lastAttributedTouchData = (attributionWindow = {}) => RNBranch.lastAttributedTouchData(attributionWindow) |
64 | | - setIdentity = (identity) => RNBranch.setIdentity(identity) |
65 | | - setIdentityAsync = (identity) => RNBranch.setIdentityAsync(identity) |
| 60 | + getLatestReferringParams = (synchronous = false) => |
| 61 | + RNBranch.getLatestReferringParams(synchronous); |
| 62 | + getFirstReferringParams = RNBranch.getFirstReferringParams; |
| 63 | + lastAttributedTouchData = (attributionWindow = {}) => |
| 64 | + RNBranch.lastAttributedTouchData(attributionWindow); |
| 65 | + setIdentity = (identity) => RNBranch.setIdentity(identity); |
| 66 | + setIdentityAsync = (identity) => RNBranch.setIdentityAsync(identity); |
66 | 67 | setRequestMetadata = (key, value) => { |
67 | | - console.info('[Branch] setRequestMetadata has limitations when called from JS. Some network calls are made prior to the JS layer being available, those calls will not have the metadata.') |
68 | | - return RNBranch.setRequestMetadataKey(key, value) |
69 | | - } |
| 68 | + console.info( |
| 69 | + "[Branch] setRequestMetadata has limitations when called from JS. Some network calls are made prior to the JS layer being available, those calls will not have the metadata." |
| 70 | + ); |
| 71 | + return RNBranch.setRequestMetadataKey(key, value); |
| 72 | + }; |
70 | 73 | addFacebookPartnerParameter = (name, value) => { |
71 | | - console.info('[Branch] addFacebookPartnerParameter has limitations when called from JS. Some network calls are made prior to the JS layer being available, those calls will not have the partner parameters.') |
72 | | - return RNBranch.addFacebookPartnerParameter(name, value) |
73 | | - } |
| 74 | + console.info( |
| 75 | + "[Branch] addFacebookPartnerParameter has limitations when called from JS. Some network calls are made prior to the JS layer being available, those calls will not have the partner parameters." |
| 76 | + ); |
| 77 | + return RNBranch.addFacebookPartnerParameter(name, value); |
| 78 | + }; |
74 | 79 | addSnapPartnerParameter = (name, value) => { |
75 | | - console.info('[Branch] addSnapPartnerParameter has limitations when called from JS. Some network calls are made prior to the JS layer being available, those calls will not have the partner parameters.') |
76 | | - return RNBranch.addSnapPartnerParameter(name, value) |
77 | | - } |
78 | | - clearPartnerParameters = RNBranch.clearPartnerParameters |
79 | | - logout = RNBranch.logout |
80 | | - getShortUrl = RNBranch.getShortUrl |
| 80 | + console.info( |
| 81 | + "[Branch] addSnapPartnerParameter has limitations when called from JS. Some network calls are made prior to the JS layer being available, those calls will not have the partner parameters." |
| 82 | + ); |
| 83 | + return RNBranch.addSnapPartnerParameter(name, value); |
| 84 | + }; |
| 85 | + clearPartnerParameters = RNBranch.clearPartnerParameters; |
| 86 | + logout = RNBranch.logout; |
| 87 | + getShortUrl = RNBranch.getShortUrl; |
81 | 88 | openURL = (url, options = {}) => { |
82 | 89 | return Platform.select({ |
83 | 90 | android: () => RNBranch.openURL(url, options), |
84 | | - ios: () => RNBranch.openURL(url) |
85 | | - })() |
86 | | - } |
| 91 | + ios: () => RNBranch.openURL(url), |
| 92 | + })(); |
| 93 | + }; |
87 | 94 | handleATTAuthorizationStatus = (ATTAuthorizationStatus) => { |
88 | | - if (Platform.OS != 'ios') return; |
89 | | - let normalizedAttAuthorizationStatus = -1 |
| 95 | + if (Platform.OS != "ios") return; |
| 96 | + let normalizedAttAuthorizationStatus = -1; |
90 | 97 |
|
91 | | - switch(ATTAuthorizationStatus) { |
92 | | - case 'authorized': |
| 98 | + switch (ATTAuthorizationStatus) { |
| 99 | + case "authorized": |
93 | 100 | normalizedAttAuthorizationStatus = 3; |
94 | 101 | break; |
95 | | - case 'denied': |
| 102 | + case "denied": |
96 | 103 | normalizedAttAuthorizationStatus = 2; |
97 | 104 | break; |
98 | | - case 'undetermined': |
| 105 | + case "undetermined": |
99 | 106 | normalizedAttAuthorizationStatus = 0; |
100 | 107 | break; |
101 | | - case 'restricted': |
| 108 | + case "restricted": |
102 | 109 | normalizedAttAuthorizationStatus = 1; |
103 | 110 | break; |
104 | 111 | } |
105 | 112 |
|
106 | 113 | if (normalizedAttAuthorizationStatus < 0) { |
107 | | - console.info('[Branch] handleATTAuthorizationStatus received an unrecognized value. Value must be one of; authorized, denied, undetermined, or restricted') |
| 114 | + console.info( |
| 115 | + "[Branch] handleATTAuthorizationStatus received an unrecognized value. Value must be one of; authorized, denied, undetermined, or restricted" |
| 116 | + ); |
108 | 117 | return; |
109 | 118 | } |
110 | 119 |
|
111 | | - RNBranch.handleATTAuthorizationStatus(normalizedAttAuthorizationStatus) |
112 | | - } |
| 120 | + RNBranch.handleATTAuthorizationStatus(normalizedAttAuthorizationStatus); |
| 121 | + }; |
113 | 122 |
|
114 | 123 | /*** BranchUniversalObject ***/ |
115 | | - createBranchUniversalObject = createBranchUniversalObject |
| 124 | + createBranchUniversalObject = createBranchUniversalObject; |
116 | 125 |
|
117 | 126 | /*** BranchQRCode ***/ |
118 | | - getBranchQRCode = (qrCodeSettings = {}, branchUniversalObject = {}, linkProperties = {}, controlParams = {}) => { |
119 | | - return RNBranch.getBranchQRCode(qrCodeSettings, branchUniversalObject, linkProperties, controlParams); |
120 | | - } |
| 127 | + getBranchQRCode = ( |
| 128 | + qrCodeSettings = {}, |
| 129 | + branchUniversalObject = {}, |
| 130 | + linkProperties = {}, |
| 131 | + controlParams = {} |
| 132 | + ) => { |
| 133 | + return RNBranch.getBranchQRCode( |
| 134 | + qrCodeSettings, |
| 135 | + branchUniversalObject, |
| 136 | + linkProperties, |
| 137 | + controlParams |
| 138 | + ); |
| 139 | + }; |
121 | 140 |
|
122 | 141 | /*** PreInstall Parameters ***/ |
123 | | - setPreInstallCampaign = (campaign) => RNBranch.setPreinstallCampaign(campaign) |
124 | | - setPreInstallPartner = (partner) => RNBranch.setPreinstallPartner(partner) |
125 | | - |
| 142 | + setPreInstallCampaign = (campaign) => |
| 143 | + RNBranch.setPreinstallCampaign(campaign); |
| 144 | + setPreInstallPartner = (partner) => RNBranch.setPreinstallPartner(partner); |
| 145 | + |
| 146 | + /*** DMA Consent Params ***/ |
| 147 | + setDMAParamsForEEA = ( |
| 148 | + eeaRegion, |
| 149 | + adPersonalizationConsent, |
| 150 | + adUserDataUsageConsent |
| 151 | + ) => { |
| 152 | + const isValid = |
| 153 | + validateParam(eeaRegion, "eeaRegion") && |
| 154 | + validateParam(adPersonalizationConsent, "adPersonalizationConsent") && |
| 155 | + validateParam(adUserDataUsageConsent, "adUserDataUsageConsent"); |
| 156 | + |
| 157 | + if (isValid) { |
| 158 | + RNBranch.setDMAParamsForEEA( |
| 159 | + eeaRegion, |
| 160 | + adPersonalizationConsent, |
| 161 | + adUserDataUsageConsent |
| 162 | + ); |
| 163 | + } else { |
| 164 | + console.warn("setDMAParamsForEEA: Unable to set DMA params."); |
| 165 | + } |
| 166 | + }; |
126 | 167 | } |
127 | 168 |
|
128 | | -export { Branch, BranchEvent, BranchSubscriber } |
129 | | -export default new Branch() |
| 169 | +const validateParam = (param, paramName) => { |
| 170 | + if (param === true || param === false) { |
| 171 | + return true; |
| 172 | + } else { |
| 173 | + console.warn( |
| 174 | + `setDMAParamsForEEA: ${paramName} must be boolean, but got ${param}` |
| 175 | + ); |
| 176 | + |
| 177 | + return false; |
| 178 | + } |
| 179 | +}; |
| 180 | + |
| 181 | +export { Branch, BranchEvent, BranchSubscriber }; |
| 182 | +export default new Branch(); |
0 commit comments