Coder Social home page Coder Social logo

Comments (2)

coluccini avatar coluccini commented on May 28, 2024

What about having the title from the state and pass it to the pageView event definitions using the nextState instead leaving GA to use current page's title?

from redux-beacon.

ttmarek avatar ttmarek commented on May 28, 2024

Hi @JacekKosciesza.

@coluccini is on the money. I would go about your problem in a very similar way.
First I would probably make a map of routes to page titles. Something like:

const pageTitles = {
  '/profile': 'Profile',
  '/accounts/payout': 'Payout',
  '/accounts/deposit': 'Deposit',
};

Then I would create a top level reducer to store the current page title in state. The reducer would listen to each ROUTER_NAVIGATION action and update the state using the url from the action payload and the map from above. Then your page view event definition could be written like so:

const pageView = (
  action: RouterNavigationAction<RouterStateSnapshot>,
  prevState, // won't need this
  nextState,
): PageView => ({
  hitType: 'pageview',
  page: action.payload.routerState.url,
  title: nextState.pageTitle, // or whatever you decide to call this property
});

This event definition would give you correct page titles in Google Analytics.

One additional benefit to this approach is you would have a single source of truth for the current page title and you could use this value from state in the ngOnInit method.

from redux-beacon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.