ReactTrackerTeko
Installation
npm install --save react-tracker-teko
Usage
Simple
import ReactTracker from "react-tracker-teko";
const reactTracker = new ReactTracker({
host: "https://tracking.tekoapis.com",
urlServeJsFile:
"https://cdn.tekoapis.com/tracker/dist/v2/tracker.full.min.js",
appId: "chat-tool",
});
const newHistory = reactTracker.connectToHistory(history);
ReactDOM.render(
<Provider store={store}>
<Router routes={routes} history={newHistory} />
</Provider>,
document.getElementById("root")
);
ReactDOM.render(
<Provider store={store}>
<Router routes={routes} history={reactTracker.connectToHistory(history)} />
</Provider>,
document.getElementById("root")
);
Advance
Auto detect
import ReactTracker, {
TrackerProvider,
useAutoPageView,
} from "react-tracker-teko";
const reactTracker = new ReactTracker({
host: "https://tracking.tekoapis.com",
urlServeJsFile:
"https://cdn.tekoapis.com/tracker/dist/v2/tracker.full.min.js",
appId: "chat-tool",
});
window.track("setUserId", "1023912");
window.track("enableTrackVisibleContentImpressions");
const routes = [
{
path: "/",
contentType: "Home",
exact: true,
screenName: "dashboard",
component: Home,
},
{ path: "/admin", contentType: "Admin", exact: true, component: Admin },
{ path: "/logs", contentType: "Log", exact: true, component: Logs },
{
path: "/logs/:id",
contentType: "Detail",
component: LogDetail,
parser: (url, match) => {
return { skuId: match.params.id };
},
},
];
ReactDOM.render(
<Provider store={store}>
<Router history={reactTracker.connectToHistory(history, routes)}>
{routes.map((route) => (
<Route {...route} key={route.path} />
))}
</Router>
</Provider>,
document.getElementById("root")
);
Support Hook define per screen
import ReactTracker, {
TrackerProvider,
useAutoPageView,
} from "react-tracker-teko";
const reactTracker = new ReactTracker({
host: "https://tracking.tekoapis.com",
urlServeJsFile:
"https://cdn.tekoapis.com/tracker/dist/v2/tracker.full.min.js",
appId: "chat-tool",
});
const ScreenA = (props) => {
track("setUserId", "random-user-id");
useAutoPageView({ screenName: "ScreenA" });
return <>ScreenA</>;
};
const ScreenB = (props) => {
const { callTrackLoadPage, callTrackUnLoadPage } = useTrackPageView();
useEffect(() => {
track("setUserId", "random-user-id");
callTrackLoadPage({ screenName: "ScreenB" });
return () => {
callTrackUnLoadPage({ screenName: "ScreenB" });
};
}, []);
return <>ScreenA</>;
};
ReactDOM.render(
<Provider store={store}>
<TrackerProvider history={browserHistory}>
<Router routes={routes} history={history} />
</TrackerProvider>
</Provider>,
document.getElementById("root")
);
Advance with content
import { TrackerProvider, useAutoPageView } from "react-tracker-teko";
new ReactTracker({
host: "https://tracking.tekoapis.com",
urlServeJsFile:
"https://cdn.tekoapis.com/tracker/dist/v2/tracker.full.min.js",
appId: "chat-tool",
});
const ScreenB = (props) => {
const { callTrackLoadPage, callTrackUnLoadPage } = useTrackPageView();
useEffect(() => {
track("setUserId", "random-user-id");
callTrackLoadPage({ screenName: "ScreenB" });
track("enableTrackVisibleContentImpressions");
return () => {
track("disableTrackVisibleContentImpressions");
callTrackUnLoadPage({ screenName: "ScreenB" });
};
}, []);
return <>ScreenA</>;
};
ReactDOM.render(
<Provider store={store}>
<TrackerProvider history={browserHistory}>
<Router routes={routes} history={history} />
</TrackerProvider>
</Provider>,
document.getElementById("root")
);
License
MIT
Change Log
Stable version: 3.2.4
[3.3.0] - 2023-06-05
Changed
- Clone function
matchPath
from react-router
v5 to avoid breaking function connectToHistory
when user react router v6. see more