From the course: Build Modern Web Apps with React, Hooks, State Management, and APIs Using Vite or Next.js

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Analytic middleware example

Analytic middleware example

Welcome back. In the previous video, we saw an example of analytics middleware and we are going to implement this example now in this video. Let's get back to the code. In the middleware's folder, we are going to add a new file analytics-middleware.ts. And here's the code from the slide. We have to import the middleware from ReduxJS toolkit. And we have to define a function and we have to define the steps that it goes through. So the steps are store next and action. In this example, we don't need the store. So we have skipped this. So we are interested in the next and the action itself. And we are writing an event here that if an action.type actually ends with fulfilled, that means that causes a success event and we can have it as analytics event success and this was the type. Then we simply return this. So inside our store where we were getting all the events for pending and fulfilled etc. Now we don't need that. We need only the success ones. So we can have the analytics middleware…

Contents