File: examples/react/src/Location-WithEffect.js

Recommend this page to a friend!
  Classes of Arturs Sosins   Countly Web SDK   examples/react/src/Location-WithEffect.js   Download  
File: examples/react/src/Location-WithEffect.js
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Countly Web SDK
Track site accesses and errors the Countly API
Author: By
Last change:
Date: 2 years ago
Size: 737 bytes
 

Contents

Class file image Download
import React from 'react'; import { useLocation } from "react-router-dom"; import Countly from 'countly-sdk-web'; const Location = (props) => { const location = useLocation(); React.useEffect(() => { //You can also check for page redirect logic or going back/forward from the browser logic here //Check if pathname is not changing dont track the view //So that you dont end up tracking the same view again and again Countly.q.push(['track_pageview', location.pathname]); // Initialize rating widget popup by current page/pathname Countly.q.push(['initializeRatingWidgets']); }, [location]); return ( <React.Fragment> {props.children} </React.Fragment> ); } export default Location;