Skip to content

Instantly share code, notes, and snippets.

@sturmenta
Last active May 28, 2023 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturmenta/2e82ccd90b26770b6d5f65c428d24f93 to your computer and use it in GitHub Desktop.
Save sturmenta/2e82ccd90b26770b6d5f65c428d24f93 to your computer and use it in GitHub Desktop.
plausible react-native expo config
import Plausible, { EventOptions, PlausibleOptions } from 'plausible-tracker';
import { setLocationHref } from '@expo/metro-runtime/build/location/Location.native.js';
// NOTE: see tracking events here: https://plausible.io/asd.xyz
const runPlausibleInitialConfig = () => {
let alreadyRun = false;
if (!alreadyRun) {
alreadyRun = true;
if (__DEV__) {
setLocationHref('https://asd.xyz/');
} else {
// @ts-ignore
window.location = {
href: 'https://asd.xyz/',
origin: 'https://asd.xyz',
protocol: 'https:',
host: 'asd.xyz',
hostname: 'asd.xyz',
port: '',
pathname: '/',
search: '',
hash: '',
};
}
// @ts-ignore
window.document = {};
}
};
const plausible = Plausible({ domain: 'asd.xyz' });
export const trackEvent = (
eventName: keyof typeof plausibleEventName,
options?: EventOptions | undefined,
eventData?: PlausibleOptions | undefined
) => {
runPlausibleInitialConfig();
plausible.trackEvent(plausibleEventName[eventName], options, eventData);
};
// NOTE: all events text must be added here
// https://plausible.io/asd.xyz/settings/goals
const plausibleEventName = {
feedback__open: 'feedback -- open',
};
// docs
// https://plausible.io/docs/goal-conversions
// https://plausible.io/docs/pageview-goals
// https://plausible.io/docs/custom-event-goals
// example
//
// trackEvent('try_to_create_home_post', {
// callback: () => console.log('sent event'),
// props: {some_data_here: 'hey, this is a analytics event 👋🏻'},
// });
@sturmenta
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment