├── .gitignore ├── LICENSE ├── Podfile ├── README.md ├── RNSegment ├── RNSegment.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcuserdata │ │ │ └── kevinstumpf.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── kevinstumpf.xcuserdatad │ │ └── xcschemes │ │ ├── RNSegment.xcscheme │ │ └── xcschememanagement.plist └── RNSegment │ ├── RNSegment.h │ └── RNSegment.m ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 DispatcherInc 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Podfile: -------------------------------------------------------------------------------- 1 | platform :ios, '8.0' 2 | 3 | xcodeproj 'RNSegment/RNSegment.xcodeproj' 4 | 5 | pod 'Analytics', '3.0.3' 6 | pod 'Segment-GoogleAnalytics', '1.0.1' 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-segment 2 | Native Wrapper around Segment's SDK 3 | 4 | This implementation automatically comes with Segment's Google Analytics client side integration. 5 | 6 | ## Usage 7 | 8 | ```js 9 | var segment = require('react-native-segment'); 10 | 11 | var debug = true; 12 | segment.setupWithConfiguration('YOUR WRITE KEY', debug); 13 | 14 | segment.identify('myUserId', {firstName: 'name'}); 15 | segment.track('Purchased Item', {itemId: 123}); 16 | segment.screen('Viewed Login'); 17 | segment.alias('myNewUserId'); 18 | segment.reset(); 19 | ``` 20 | 21 | ## Installation 22 | 23 | ```sh 24 | npm install --save react-native-segment 25 | cd node_modules/react-native-segment 26 | pod install 27 | ``` 28 | 29 | ### Modifications to your React Native XCode Project 30 | 31 | - Drag and Drop /node_modules/react-native-segment/RNSegment/RNSegment.xcodeproj into the Libraries folder of your project in XCode (as described [here](https://facebook.github.io/react-native/docs/linking-libraries-ios.html#content)) 32 | - Drag and Drop the RNSegment's libRNSegment.a from its Products folder into your project's target's "Linked Frameworks and Libraries" section (again, as described [here](https://facebook.github.io/react-native/docs/linking-libraries-ios.html#content)) 33 | - Similarly, Drag and Drop /node_modules/react-native-segment/Pods/Pods.xcodeproj into the Libraries folder of your project 34 | - Drag and Drop the Pod's libAnalytics.a and libSegment-GoogleAnalytics.a into your project's target's "Linked Frameworks and Libraries" section 35 | - Drag and Drop /Libraries/Pods.xcodeproj/Pods/GoogleAnalytics/Frameworks/libGoogleAnalytics.a into the root of your project 36 | - Add the following path to your project's "Library Search Paths" 37 | ```sh 38 | "$(SRCROOT)/../node_modules/react-native-segment/Pods/GoogleAnalytics/Libraries" 39 | ``` 40 | - Add the following Linked Frameworks and Libraries to your project: "CoreData.framework", "CFNetwork.framework", "libsqlite3.tbd", "libz.tbd" 41 | -------------------------------------------------------------------------------- /RNSegment/RNSegment.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B3DFA0A41C268EEF008F4178 /* RNSegment.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = B3DFA0A31C268EEF008F4178 /* RNSegment.h */; }; 11 | B3DFA0A61C268EEF008F4178 /* RNSegment.m in Sources */ = {isa = PBXBuildFile; fileRef = B3DFA0A51C268EEF008F4178 /* RNSegment.m */; }; 12 | /* End PBXBuildFile section */ 13 | 14 | /* Begin PBXCopyFilesBuildPhase section */ 15 | B3DFA09E1C268EEF008F4178 /* CopyFiles */ = { 16 | isa = PBXCopyFilesBuildPhase; 17 | buildActionMask = 2147483647; 18 | dstPath = "include/$(PRODUCT_NAME)"; 19 | dstSubfolderSpec = 16; 20 | files = ( 21 | B3DFA0A41C268EEF008F4178 /* RNSegment.h in CopyFiles */, 22 | ); 23 | runOnlyForDeploymentPostprocessing = 0; 24 | }; 25 | /* End PBXCopyFilesBuildPhase section */ 26 | 27 | /* Begin PBXFileReference section */ 28 | 284E63307FF018D2B6C16083 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; 29 | 9645C2863A4601780C4D4670 /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "../Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = ""; }; 30 | A6F64B1F5F6B837D2D2A73F8 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "../Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; 31 | B3DFA0A01C268EEF008F4178 /* libRNSegment.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNSegment.a; sourceTree = BUILT_PRODUCTS_DIR; }; 32 | B3DFA0A31C268EEF008F4178 /* RNSegment.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNSegment.h; sourceTree = ""; }; 33 | B3DFA0A51C268EEF008F4178 /* RNSegment.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNSegment.m; sourceTree = ""; }; 34 | /* End PBXFileReference section */ 35 | 36 | /* Begin PBXFrameworksBuildPhase section */ 37 | B3DFA09D1C268EEF008F4178 /* Frameworks */ = { 38 | isa = PBXFrameworksBuildPhase; 39 | buildActionMask = 2147483647; 40 | files = ( 41 | ); 42 | runOnlyForDeploymentPostprocessing = 0; 43 | }; 44 | /* End PBXFrameworksBuildPhase section */ 45 | 46 | /* Begin PBXGroup section */ 47 | B3DFA0971C268EEE008F4178 = { 48 | isa = PBXGroup; 49 | children = ( 50 | B3DFA0A21C268EEF008F4178 /* RNSegment */, 51 | B3DFA0A11C268EEF008F4178 /* Products */, 52 | F761A531F7277E1F6051B22C /* Pods */, 53 | BD976673584927699D0C23DF /* Frameworks */, 54 | ); 55 | sourceTree = ""; 56 | }; 57 | B3DFA0A11C268EEF008F4178 /* Products */ = { 58 | isa = PBXGroup; 59 | children = ( 60 | B3DFA0A01C268EEF008F4178 /* libRNSegment.a */, 61 | ); 62 | name = Products; 63 | sourceTree = ""; 64 | }; 65 | B3DFA0A21C268EEF008F4178 /* RNSegment */ = { 66 | isa = PBXGroup; 67 | children = ( 68 | B3DFA0A31C268EEF008F4178 /* RNSegment.h */, 69 | B3DFA0A51C268EEF008F4178 /* RNSegment.m */, 70 | ); 71 | path = RNSegment; 72 | sourceTree = ""; 73 | }; 74 | BD976673584927699D0C23DF /* Frameworks */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | 284E63307FF018D2B6C16083 /* libPods.a */, 78 | ); 79 | name = Frameworks; 80 | sourceTree = ""; 81 | }; 82 | F761A531F7277E1F6051B22C /* Pods */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | A6F64B1F5F6B837D2D2A73F8 /* Pods.debug.xcconfig */, 86 | 9645C2863A4601780C4D4670 /* Pods.release.xcconfig */, 87 | ); 88 | name = Pods; 89 | sourceTree = ""; 90 | }; 91 | /* End PBXGroup section */ 92 | 93 | /* Begin PBXNativeTarget section */ 94 | B3DFA09F1C268EEF008F4178 /* RNSegment */ = { 95 | isa = PBXNativeTarget; 96 | buildConfigurationList = B3DFA0A91C268EEF008F4178 /* Build configuration list for PBXNativeTarget "RNSegment" */; 97 | buildPhases = ( 98 | B3DFA09C1C268EEF008F4178 /* Sources */, 99 | B3DFA09D1C268EEF008F4178 /* Frameworks */, 100 | B3DFA09E1C268EEF008F4178 /* CopyFiles */, 101 | ); 102 | buildRules = ( 103 | ); 104 | dependencies = ( 105 | ); 106 | name = RNSegment; 107 | productName = RNSegment; 108 | productReference = B3DFA0A01C268EEF008F4178 /* libRNSegment.a */; 109 | productType = "com.apple.product-type.library.static"; 110 | }; 111 | /* End PBXNativeTarget section */ 112 | 113 | /* Begin PBXProject section */ 114 | B3DFA0981C268EEE008F4178 /* Project object */ = { 115 | isa = PBXProject; 116 | attributes = { 117 | LastUpgradeCheck = 0710; 118 | ORGANIZATIONNAME = Dispatcher; 119 | TargetAttributes = { 120 | B3DFA09F1C268EEF008F4178 = { 121 | CreatedOnToolsVersion = 7.1.1; 122 | }; 123 | }; 124 | }; 125 | buildConfigurationList = B3DFA09B1C268EEE008F4178 /* Build configuration list for PBXProject "RNSegment" */; 126 | compatibilityVersion = "Xcode 3.2"; 127 | developmentRegion = English; 128 | hasScannedForEncodings = 0; 129 | knownRegions = ( 130 | en, 131 | ); 132 | mainGroup = B3DFA0971C268EEE008F4178; 133 | productRefGroup = B3DFA0A11C268EEF008F4178 /* Products */; 134 | projectDirPath = ""; 135 | projectRoot = ""; 136 | targets = ( 137 | B3DFA09F1C268EEF008F4178 /* RNSegment */, 138 | ); 139 | }; 140 | /* End PBXProject section */ 141 | 142 | /* Begin PBXSourcesBuildPhase section */ 143 | B3DFA09C1C268EEF008F4178 /* Sources */ = { 144 | isa = PBXSourcesBuildPhase; 145 | buildActionMask = 2147483647; 146 | files = ( 147 | B3DFA0A61C268EEF008F4178 /* RNSegment.m in Sources */, 148 | ); 149 | runOnlyForDeploymentPostprocessing = 0; 150 | }; 151 | /* End PBXSourcesBuildPhase section */ 152 | 153 | /* Begin XCBuildConfiguration section */ 154 | B3DFA0A71C268EEF008F4178 /* Debug */ = { 155 | isa = XCBuildConfiguration; 156 | buildSettings = { 157 | ALWAYS_SEARCH_USER_PATHS = NO; 158 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 159 | CLANG_CXX_LIBRARY = "libc++"; 160 | CLANG_ENABLE_MODULES = YES; 161 | CLANG_ENABLE_OBJC_ARC = YES; 162 | CLANG_WARN_BOOL_CONVERSION = YES; 163 | CLANG_WARN_CONSTANT_CONVERSION = YES; 164 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 165 | CLANG_WARN_EMPTY_BODY = YES; 166 | CLANG_WARN_ENUM_CONVERSION = YES; 167 | CLANG_WARN_INT_CONVERSION = YES; 168 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 169 | CLANG_WARN_UNREACHABLE_CODE = YES; 170 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 171 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 172 | COPY_PHASE_STRIP = NO; 173 | DEBUG_INFORMATION_FORMAT = dwarf; 174 | ENABLE_STRICT_OBJC_MSGSEND = YES; 175 | ENABLE_TESTABILITY = YES; 176 | GCC_C_LANGUAGE_STANDARD = gnu99; 177 | GCC_DYNAMIC_NO_PIC = NO; 178 | GCC_NO_COMMON_BLOCKS = YES; 179 | GCC_OPTIMIZATION_LEVEL = 0; 180 | GCC_PREPROCESSOR_DEFINITIONS = ( 181 | "DEBUG=1", 182 | "$(inherited)", 183 | ); 184 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 185 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 186 | GCC_WARN_UNDECLARED_SELECTOR = YES; 187 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 188 | GCC_WARN_UNUSED_FUNCTION = YES; 189 | GCC_WARN_UNUSED_VARIABLE = YES; 190 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 191 | MTL_ENABLE_DEBUG_INFO = YES; 192 | ONLY_ACTIVE_ARCH = YES; 193 | SDKROOT = iphoneos; 194 | }; 195 | name = Debug; 196 | }; 197 | B3DFA0A81C268EEF008F4178 /* Release */ = { 198 | isa = XCBuildConfiguration; 199 | buildSettings = { 200 | ALWAYS_SEARCH_USER_PATHS = NO; 201 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 202 | CLANG_CXX_LIBRARY = "libc++"; 203 | CLANG_ENABLE_MODULES = YES; 204 | CLANG_ENABLE_OBJC_ARC = YES; 205 | CLANG_WARN_BOOL_CONVERSION = YES; 206 | CLANG_WARN_CONSTANT_CONVERSION = YES; 207 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 208 | CLANG_WARN_EMPTY_BODY = YES; 209 | CLANG_WARN_ENUM_CONVERSION = YES; 210 | CLANG_WARN_INT_CONVERSION = YES; 211 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 212 | CLANG_WARN_UNREACHABLE_CODE = YES; 213 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 214 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 215 | COPY_PHASE_STRIP = NO; 216 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 217 | ENABLE_NS_ASSERTIONS = NO; 218 | ENABLE_STRICT_OBJC_MSGSEND = YES; 219 | GCC_C_LANGUAGE_STANDARD = gnu99; 220 | GCC_NO_COMMON_BLOCKS = YES; 221 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 222 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 223 | GCC_WARN_UNDECLARED_SELECTOR = YES; 224 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 225 | GCC_WARN_UNUSED_FUNCTION = YES; 226 | GCC_WARN_UNUSED_VARIABLE = YES; 227 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 228 | MTL_ENABLE_DEBUG_INFO = NO; 229 | SDKROOT = iphoneos; 230 | VALIDATE_PRODUCT = YES; 231 | }; 232 | name = Release; 233 | }; 234 | B3DFA0AA1C268EEF008F4178 /* Debug */ = { 235 | isa = XCBuildConfiguration; 236 | baseConfigurationReference = A6F64B1F5F6B837D2D2A73F8 /* Pods.debug.xcconfig */; 237 | buildSettings = { 238 | HEADER_SEARCH_PATHS = ( 239 | "$(inherited)", 240 | "$(SRCROOT)/../../react-native/React/**", 241 | "\"$(SRCROOT)/../../../ios/Pods/Headers/Public\"", 242 | ); 243 | OTHER_LDFLAGS = "-ObjC"; 244 | PRODUCT_NAME = "$(TARGET_NAME)"; 245 | SKIP_INSTALL = YES; 246 | }; 247 | name = Debug; 248 | }; 249 | B3DFA0AB1C268EEF008F4178 /* Release */ = { 250 | isa = XCBuildConfiguration; 251 | baseConfigurationReference = 9645C2863A4601780C4D4670 /* Pods.release.xcconfig */; 252 | buildSettings = { 253 | HEADER_SEARCH_PATHS = ( 254 | "$(inherited)", 255 | "$(SRCROOT)/../../react-native/React/**", 256 | "\"$(SRCROOT)/../../../ios/Pods/Headers/Public\"", 257 | ); 258 | OTHER_LDFLAGS = "-ObjC"; 259 | PRODUCT_NAME = "$(TARGET_NAME)"; 260 | SKIP_INSTALL = YES; 261 | }; 262 | name = Release; 263 | }; 264 | /* End XCBuildConfiguration section */ 265 | 266 | /* Begin XCConfigurationList section */ 267 | B3DFA09B1C268EEE008F4178 /* Build configuration list for PBXProject "RNSegment" */ = { 268 | isa = XCConfigurationList; 269 | buildConfigurations = ( 270 | B3DFA0A71C268EEF008F4178 /* Debug */, 271 | B3DFA0A81C268EEF008F4178 /* Release */, 272 | ); 273 | defaultConfigurationIsVisible = 0; 274 | defaultConfigurationName = Release; 275 | }; 276 | B3DFA0A91C268EEF008F4178 /* Build configuration list for PBXNativeTarget "RNSegment" */ = { 277 | isa = XCConfigurationList; 278 | buildConfigurations = ( 279 | B3DFA0AA1C268EEF008F4178 /* Debug */, 280 | B3DFA0AB1C268EEF008F4178 /* Release */, 281 | ); 282 | defaultConfigurationIsVisible = 0; 283 | defaultConfigurationName = Release; 284 | }; 285 | /* End XCConfigurationList section */ 286 | }; 287 | rootObject = B3DFA0981C268EEE008F4178 /* Project object */; 288 | } 289 | -------------------------------------------------------------------------------- /RNSegment/RNSegment.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /RNSegment/RNSegment.xcodeproj/project.xcworkspace/xcuserdata/kevinstumpf.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevinstumpf/react-native-segment/6ec90eed35392bb23e23c25046545a266683ed22/RNSegment/RNSegment.xcodeproj/project.xcworkspace/xcuserdata/kevinstumpf.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /RNSegment/RNSegment.xcodeproj/xcuserdata/kevinstumpf.xcuserdatad/xcschemes/RNSegment.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /RNSegment/RNSegment.xcodeproj/xcuserdata/kevinstumpf.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | RNSegment.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | B3DFA09F1C268EEF008F4178 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /RNSegment/RNSegment/RNSegment.h: -------------------------------------------------------------------------------- 1 | // 2 | // RNSegment.h 3 | // RNSegment 4 | // 5 | // Created by Kevin Stumpf on 12/19/15. 6 | // Copyright © 2015 Dispatcher. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "RCTBridgeModule.h" 12 | 13 | @interface RNSegment : NSObject 14 | 15 | @end -------------------------------------------------------------------------------- /RNSegment/RNSegment/RNSegment.m: -------------------------------------------------------------------------------- 1 | // 2 | // RNSegment.m 3 | // RNSegment 4 | // 5 | // Created by Kevin Stumpf on 12/19/15. 6 | // Copyright © 2015 Dispatcher. All rights reserved. 7 | // 8 | 9 | #import "RNSegment.h" 10 | #import 11 | #import 12 | #import "RCTBridgeModule.h" 13 | 14 | @implementation RNSegment 15 | 16 | RCT_EXPORT_MODULE(); 17 | 18 | RCT_EXPORT_METHOD(setupWithConfiguration:(NSString *)writeKey withDebug:(BOOL)debug) 19 | { 20 | SEGAnalyticsConfiguration *config = [SEGAnalyticsConfiguration configurationWithWriteKey:writeKey]; 21 | [config use:[SEGGoogleAnalyticsIntegrationFactory instance]]; 22 | [SEGAnalytics setupWithConfiguration:config]; 23 | [SEGAnalytics debug:debug]; 24 | } 25 | 26 | RCT_EXPORT_METHOD(identify:(NSString *)userId withTraits:(NSDictionary *)traits withOptions:(NSDictionary *)options) 27 | { 28 | [[SEGAnalytics sharedAnalytics] identify:userId traits:traits options:options]; 29 | } 30 | 31 | RCT_EXPORT_METHOD(track:(NSString *)event withProperties:(NSDictionary *)properties withOptions:(NSDictionary *)options) 32 | { 33 | [[SEGAnalytics sharedAnalytics] track:event properties:properties options:options]; 34 | } 35 | 36 | RCT_EXPORT_METHOD(screen:(NSString *)name withProperties:(NSDictionary *)properties withOptions:(NSDictionary *)options) 37 | { 38 | [[SEGAnalytics sharedAnalytics] screen:name properties:properties options:options]; 39 | } 40 | 41 | RCT_EXPORT_METHOD(alias:(NSString *)newId withOptions:(NSDictionary *)options) 42 | { 43 | [[SEGAnalytics sharedAnalytics] alias:newId options:options]; 44 | } 45 | 46 | RCT_EXPORT_METHOD(reset) 47 | { 48 | [[SEGAnalytics sharedAnalytics] reset]; 49 | } 50 | @end 51 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var { NativeModules, Platform } = require('react-native'); 2 | 3 | var rnSegment = Platform.OS === 'ios' ? NativeModules.RNSegment : null; 4 | 5 | class Segment { 6 | setupWithConfiguration = (writeKey, debug = false) => { 7 | if(!rnSegment) { 8 | return; 9 | } 10 | 11 | rnSegment.setupWithConfiguration(writeKey, debug); 12 | }; 13 | 14 | identify = (userId, traits = {}, options = {}) => { 15 | if(!rnSegment) { 16 | return; 17 | } 18 | 19 | rnSegment.identify(userId, traits, options); 20 | }; 21 | 22 | track = (event, properties = {}, options = {}) => { 23 | if(!rnSegment) { 24 | return; 25 | } 26 | 27 | rnSegment.track(event, properties, options); 28 | }; 29 | 30 | screen = (event, properties = {}, options = {}) => { 31 | if(!rnSegment) { 32 | return; 33 | } 34 | 35 | rnSegment.screen(event, properties, options); 36 | }; 37 | 38 | alias = (newid, options = {}) => { 39 | if(!rnSegment) { 40 | return; 41 | } 42 | 43 | rnSegment.alias(newId, options); 44 | }; 45 | 46 | reset = () => { 47 | if(!rnSegment) { 48 | return; 49 | } 50 | 51 | rnSegment.reset(); 52 | }; 53 | } 54 | 55 | export default new Segment(); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-segment", 3 | "version": "1.0.2", 4 | "description": "Native Wrapper around Segment's SDK", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/DispatcherInc/react-native-segment.git" 12 | }, 13 | "keywords": [ 14 | "react-native", 15 | "react-component", 16 | "ios", 17 | "segment" 18 | ], 19 | "author": "Kevin Stumpf", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/DispatcherInc/react-native-segment/issues" 23 | }, 24 | "homepage": "https://github.com/DispatcherInc/react-native-segment#readme" 25 | } 26 | --------------------------------------------------------------------------------