Skip to content

Instantly share code, notes, and snippets.

@iswanj
Created May 24, 2021 13:26
Show Gist options
  • Save iswanj/7e97e1f1db3a5f823b2670249bb60444 to your computer and use it in GitHub Desktop.
Save iswanj/7e97e1f1db3a5f823b2670249bb60444 to your computer and use it in GitHub Desktop.
Tracking Custom mixpanel events
import React from 'react';
import { View, Text } from 'react-native';
import {Button} from 'components';
import {useMixpanel} from 'provider/MixpanelProvider'; // import useMixpanel hooks
const MyComponent = () => {
const mixpanel = useMixpanel(); // put this code top of your functional component
const handleTrack = () => {
// here you can use any mixpanel methods
// e.g.
// mixpanel.timeEvent("Image Upload");
// mixpanel.track("Image Upload");
// mixpanel.registerSuperProperties({'Plan': 'Mega', 'Cost': '2000'});
// mixpanel.clearSuperProperties();
// mixpanel.identify("13791");
// mixpanel.alias('new_id', 'existing_id');
mixpanel.track('Clicked Track me button');
}
return (
<View>
<Text>My Component</Text>
<Button onPress={handleTrack}><Text>Track me</Text></Button>
</View>
)
};
export default MyComponent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment