Monthly Archives: November 2019

Use spring +aspectj in Spring boot

compile('org.springframework.boot:spring-boot-starter-aop')
compile('org.aspectj:aspectjrt')
compile('org.aspectj:aspectjweaver')
@SpringBootApplication
@EnableAspectJAutoProxy(proxyTargetClass=true)
public class YourApplication ...{
...
}
@Component
@Aspect
public class YourAspect {

	@Before("execution(public * com..*Manager.*(..))")
	public void doAdvice(JoinPoint joinPoint) {...}
	 
}

Enable google analytics with react-router

One way of doing this is to create your own Router class, which extends the one from the framework; and inside this Router class you put in the tracking logic:

class MyRouteComponent extends React.Component<Props, State> {

    constructor(props: Props) {
        super(props);
        this.state = {currentUserRefreshed: false};

        if (isProdEnv()) {
            ReactGA.initialize('UA-GOOGLE-ANAYLTICS-ID');
        }
    }

    trackPage(pageUrl:string) {
        ReactGA.set({page: pageUrl});
        ReactGA.pageview(pageUrl);
    }

    toPageUrl(location: Location) {
        return location.pathname + location.search;
    }

    componentDidMount() {
        this.props.refreshCurrentUser();

        if(isProdEnv() && this.props.location){
            this.trackPage(this.toPageUrl(this.props.location!));
        }
    }

    render() {
        ...
    }
}