- Capacitor wrapper plugin for Segment analytics mobile SDK.
- Only implemented on iOS and Android (not for PWA)
$ yarn add @jairemix/capacitor-segment
$ yarn cap sync
$ npm install @jairemix/capacitor-segment
$ npx cap sync
After installing and syncing the Capacitor plugin, remember to add it to MainActivity.java
// Other Imports
import com.jairemix.capacitor.segment.SegmentPlugin;
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initializes the Bridge
this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
add(SegmentPlugin.class);
// Additional plugins you've installed go here
}});
}
}
import { segmentPlugin } from '@jairemix/capacitor-segment';
async function test() {
await segmentPlugin.setUp({
key: 'test_key',
trackLifecycle: true, // optional; defaults to false
});
await segmentPlugin.identify({
userID: 'jake_peralta',
traits: { // optional
noice: true,
smort: true,
toit: true,
},
});
await segmentPlugin.track({
eventName: 'item_ordered',
properties: { // optional
itemID: 'orange_soda',
},
});
await segmentPlugin.reset(); // on logout
}
Passes segment key to Segment SDK
Sets userID in Segment SDK
Tracks a Segment event
Clears previously set userID