A simple script to integrate Google Analytics into React Starter Kit projects.
Install package by running
npm install ga-react --save
OR
yarn add ga-react
Usage in class component
const tawkTo = require("tawkto-react");
// note this is not just property id, but the string after the slash (/) as well
const tawkToPropertyId = 'get_property_id_from_tawkto_dashboard'
componentDidMount(){
tawkTo(tawkToPropertyId)
}
Usage in functional component
const tawkTo = require("tawkto-react");
const tawkToPropertyId = 'get_property_id_from_tawkto_dashboard'
useEffect(() => {
tawkTo(tawkToPropertyId)
}, [])
Function must be called after the DOM is loaded, such as inside componentDidMount or useEffect.
- Abhinav Das