Last active
October 31, 2024 17:03
-
-
Save sturmenta/2e82ccd90b26770b6d5f65c428d24f93 to your computer and use it in GitHub Desktop.
plausible react-native expo config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 👋🏻'}, | |
// }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks to @brentvatne for find one hack to use plausible on react-native