๐ฉโ๐งโ๐ฆ marketing Analytics ๊ณตํต๋ชจ๋ ์ ์๊ธฐ
KEY idx |
hitDate |
hitCode |
hitUid |
pageURL |
pageType |
---|---|---|---|---|---|
3 | 2024-12-10 11-45-12.13 | a2FrYW8xc3QK | f2843ad6-2de0-48d2-9b5d-3b0eb4f9a4f5 | sp/loan | GET |
2 | 2024-12-10 12-40-11.22 | AAA22dfxdfw2 | 94107590-2b39-478f-9bb3-32f4a8ef68cb | sp/loan/mortgage/notice | GET |
1 | 2024-12-09 12-40-11.22 | aWfeYW8xc222 | 3eac413b-a95b-44f8-8f12-32ec4be98e39 | sp/marketing/hitTest1 | POST |
- ๊ด์ฌ์ฌ(Aspect)๋ฅผ ๋ถ๋ฆฌํ์ฌ, ๊ฐ ์๋น์ค ๋ฉ์๋์ ๋ฐ๋ณตํด์ ๊ตฌํํ๋ ๊ฒ์ด ์๋, ๋ณ๋์ Aspect๋ก ๊ด๋ฆฌํ์ฌ ํต์ฌ๋ก์ง์ ๊ณตํต์ผ๋ก ์ ์ฉํ๊ธฐ ์ํจ์ด๋ค.
Path๋ฅผ ๋ช ์์ ์ผ๋ก ์ค์ ํ์ฌ ์ฃผ์ง ์์์ ๋, ์ฟ ํค๊ฐ ๋ฑ๋ก๋์ง ์๋ ์ด์
์ฟ ํค๊ฐ ํ์ํ ํ์ด์ง์ ๊ฒฝ๋ก๊ฐ ๊ธฐ๋ณธ path
์ ์ผ์นํ๋ ๊ฒฝ์ฐ(redirect url
์ด SP_MARKETING_HIT_TEST1
์ ํ์ url์ผ ๊ฒฝ์ฐ)
์๋ ๋ช
์์ ์ผ๋ก ํ์ํ ํ์๊ฐ ์์ง๋ง,
๊ธฐ์กด
DB
@Pointcut
์ด๋
ธํ
์ด์
์ ์ปดํ์ผ ์์ ์ ๊ณ ์ ๋ ๋ฌธ์์ด๋ก ์ ์๋ ํฌ์ธํธ์ปท ํํ์์ ๊ธฐ๋ฐ์ผ๋ก ๋์ํ๋ค.- ํฌ์ธํธ์ปท ์กฐ๊ฑด์ ์ปดํ์ผ ์์ ์ ๊ณ ์ ๋๋ค.
- ๋ณต์กํ ์กฐ๊ฑด์ด๋ ๋์ ์ผ๋ก ๋ณ๊ฒฝ๋๋ ์กฐ๊ฑด์ ์ฒ๋ฆฌํ๊ธฐ ์ด๋ ต๋ค.
-> @Pointcut
๋ฑ์ ์กฐ๊ฑด์ ๋ถํฉํ๋ Bean๊ฐ์ฒด๋ฅผ ์ปดํ์ผ ์์ ์ ์ฐพ์๋ด์ด ํ๋ก์๋ฅผ ๊ฐ์ผ๋ค.StaticMethodMatcherPointcut
๋๋ DynamicMethodMatcherPointcut
์ ์ฌ์ฉํ์ฌ ๋ฐํ์ ์กฐ๊ฑด ๊ธฐ๋ฐ์ผ๋ก ๋ฉ์๋ ๋งค์นญ.-> ํด๋น ํ๋ก์ ๊ฐ์ฒด๋ฅผ ์ ์ฉํ๊ณ ์ถ์ Bean๊ฐ์ฒด
์ ๋งค๋ฒ ์์ฑ(๋ฑ๋ก)ํด์ฃผ์ด์ผ ํจ.
import org.springframework.aop.Pointcut;
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class AopConfig {
@Bean
public Pointcut customPointcut() {
return new CustomPointcut();
}
@Bean
public CustomAdvice customAdvice() {
return new CustomAdvice();
}
@Bean
public DefaultPointcutAdvisor customAdvisor(Pointcut customPointcut, CustomAdvice customAdvice) {
return new DefaultPointcutAdvisor(customPointcut, customAdvice);
}
@Bean
public DefaultAdvisorAutoProxyCreator proxyCreator() {
return new DefaultAdvisorAutoProxyCreator();
}
}
DefaultAdvisorAutoProxyCreator
๊ฐ์ฒด๊ฐ ์กฐ๊ฑด์ ๋ถํฉํ๋ ๋น์ ๋ํด ์๋์ผ๋ก ํ๋ก์๋ฅผ ์์ฑํ์ฌ Advice
๋ฅผ ์ ์ฉํ๋ค.@Pointcut
๋ฐฉ์๊ณผ ๋์ผํ ๋์:
DefaultAdvisorAutoProxyCreator
๋ ์ด๋ป๊ฒ customAdvisor
์ ์กฐ๊ฑด์ ๋ถํฉํ๋ ๋น์ ์ฐพ๋?DefaultAdvisorAutoProxyCreator
๋ Spring์ BeanPostProcessor
๋ฅผ ๊ตฌํํ ํด๋์ค์ด๋ค.BeanPostProcessor
๋ฅผ ์๋์ผ๋ก ํธ์ถํ์ฌ ๋น์ ์ด๊ธฐํ ์ ํ ์์
์ ์ํํ๋ค.DefaultAdvisorAutoProxyCreator
๋ Spring ์ปจํ
์คํธ์ ๋ฑ๋ก๋ ๋ชจ๋ Advisor๋ฅผ ์๋์ผ๋ก ํ์ํ๋ค.DefaultAdvisorAutoProxyCreator
๊ฐ BeanFactory
๋ฅผ ํตํด ์ปจํ
์ด๋์ ๋ชจ๋ Advisor
ํ์
๋น์ ์กฐํํ๊ธฐ ๋๋ฌธ.Advisor
๋ฅผ ์ฌ์ฉํ์ฌ ๊ฐ ๋น์ ๋ฉ์๋์ ํฌ์ธํธ์ปท ์กฐ๊ฑด์ ๋งค์นญ.DefaultAdvisorAutoProxyCreator
๋ ํด๋น ๋น์ ๋ฉ์๋๊ฐ ์ด๋ค Advisor
์ ํฌ์ธํธ์ปท ์กฐ๊ฑด์ ๋ถํฉํ๋์ง ํ๊ฐ./*
* EnableAspectJAutoProxy > ํ๋ก์ ์ ์ฉ์ ์ธํฐํ์ด์ค/ํด๋์ค ์ฌ๋ถ ์๋ ํ๋จ
* ํด๋์ค์ ์ธํฐํ์ด์ค๊ฐ ์์ผ๋ฉด JDK ๋์ ํ๋ก์.
* ์ธํฐํ์ด์ค๊ฐ ์์ผ๋ฉด CGLIB ํ๋ก์.
* */@Configuration
@EnableAspectJAutoProxy
public class AopConfig {
@Bean
public Pointcut customPointcut() {
return new CustomPointcut();
}
@Bean
public CustomAdvice customAdvice() {
return new CustomAdvice();
}
@Bean
public DefaultPointcutAdvisor customAdvisor(Pointcut customPointcut, CustomAdvice customAdvice) {
return new DefaultPointcutAdvisor(customPointcut, customAdvice);
}
/*
* @EnableAspectJAutoProxy๋ฅผ ์ฌ์ฉํด ๋ฑ๋กํ๊ธฐ ๋๋ฌธ์ ๋ถํ์.
* */
// @Bean
// public DefaultAdvisorAutoProxyCreator proxyCreator() {
// return new DefaultAdvisorAutoProxyCreator();
// }
}
Method Name: loanerLoginPage javax.servlet.http.HttpServletRequest org.springframework.web.bind.annotation.GetMapping
์ดํ DB์ ๋งตํํ์ฌ admin์์ ์๋์ผ๋ก ๊ด๋ฆฌ๋ก ๋ณ๊ฒฝ ๋จ.
"p"ํ๋ผ๋ฏธํฐ
๊ฐ ์์๋,hitCode
/ hitUid
๊ฐ ์์๋hitCode
/ hitUid
๊ฐ ์์๋"p"ํ๋ผ๋ฏธํฐ
๋ก ์ฌ๋ฐ๊ธ
=> hitCode
๋ ๋งค๋ฒ ์ฌ๋ฐ๊ธ / hitUid
๋ ์์๋๋ง ๋ฐ๊ธ"p"ํ๋ผ๋ฏธํฐ
๊ฐ ์์๋,hitCode
/ hitUid
๊ฐ ๋๋ค ์์๋hitUid
๋๋ hitUid
๊ฐ ์์๋@Override
@Transactional
public ResponseModel insertMarketingHitLog(String hitCode, String hitUid, String pageUrl, String pageType){
try {
Optional<HfMarketingHitLog> existingLog = hfMarketingHitLogRepository.findByHitCodeAndHitUidAndPageUrlAndPageType(hitCode, hitUid, pageUrl, pageType);
if (existingLog.isPresent()) {
HfMarketingHitLog logToUpdate = existingLog.get();
logToUpdate.setUpdateDate(LocalDateTime.now());
hfMarketingHitLogRepository.save(logToUpdate);
return new ResponseModel(ResponseModel.ResponseStatus.SUCCESS);
}
HfMarketingHitLog hfMarketingHitLog = HfMarketingHitLog.builder()
.hitCode(hitCode)
.hitUid(hitUid)
.pageUrl(pageUrl)
.pageType(pageType)
.build();
hfMarketingHitLogRepository.save(hfMarketingHitLog);
return new ResponseModel(ResponseModel.ResponseStatus.SUCCESS);
} catch (Exception e) {
return new ResponseModel(ResponseModel.ResponseStatus.FAILED, "๋ฐ์ดํฐ ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์");
}
}
findByHitCodeAndHitUidAndPageUrlAndPageType
๋ฉ์๋๋ฅผ ํธ์ถํ์ฌ ๋์ผํ ์กฐ๊ฑด์ ๋ฐ์ดํฐ๋ฅผ ๋์์ ์กฐํํ ์ ์๋ค.existingLog.isPresent()
์กฐ๊ฑด์์ false
๋ฅผ ํ์ธํ ํ, ๋์์ ์๋ก์ด HfMarketingHitLog
๊ฐ์ฒด๋ฅผ ์์ฑํ๊ณ ์ ์ฅํ๋ ค ํ๋ฉด ๋ฐ์ดํฐ ์ค๋ณต ๋ฌธ์ ๊ฐ ๋ฐ์ํ ์ ์๋ค.. Lock์ ์ฐ๋ฉด ๋๋, ์ดํ ์ ๋ฐ์ดํธ ๋ก์ง ์ญ์ (๋ก๊ทธ ํ ์ด๋ธํ) ๋ณ๊ฒฝ์ผ๋ก ์ฒ๋ฆฌ
page_url
๋ ์ฝ๋์ ๋ฏธ๋ฆฌ ๋ฑ๋ก / hit_code
๋ ๋ชจ๋(only ์๋ฌธ+์ซ์) ์์ฉ ๊ฐ๋ฅ
=> ํด๋นํ๋ ๋ถ๋ถ์ ๋ฆฌ๋น๋์ ํฐ ์ฐจ์ด๊ฐ ์๊ณ , ๊ฐ class์ scope๋ฅผ ๋ฐ๋ก ์ ์ฉํด์ผํ๊ธฐ ๋๋ฌธ์ ๊ณ ๋ คํ์ง ์์๋ค.
=> ์ฐ๊ด์ฑ ์๋ ๋ชจ๋ ์ฐธ์กฐ๋ฅผ ์๋์ผ๋ก ์ฌ์ค์ ํด์ผํ๊ธฐ ๋๋ฌธ์ ๋งค์ฐ ๋ณต์กํด์ง๋ค.
๋ด๋ถํต๊ณ๊ธฐ๋ฅ(AOP)์ ์ง์ URL์์ ๋ค์ด๋ฒ ์๋ ๋ฆฌํฑ์ค(์ธ๋ถ ํต๊ณ ํ๋ก๊ทธ๋จ)๊ฐ ์๋ํ์ง ์๋ ์ด์
<html xmlns:th="http://www/thymeleaf.org" th:replace="layout/mainLayout :: mainLayout('gate loan')">
<script th:inline="javascript">
$(document).ready(function() {
location.href = [[${urls.SP_LOAN}]];
});
</script>
mainLayout์ ์ ์ฉํ์ฌ ํด๋น ํ์ด์ง์ default script๋ฅผ ์ ์ฉ์์ผฐ๋ค. ๊ฒฐ๊ณผ๋ ์ถํ ๋ชจ๋ํฐ๋ง ์์
sp/loan๊ธฐ์ค์ผ๋ก ๋ ํผ๋ฌ๋ฅผ https://www-stg.hellofunding.co.kr/sp/loan/gtLoan?p=Z29vZ2xlMXN0
์ธ์
ํ์ด์ง ์ฃผ์๋ฅผ ๊ฐ๊ณ ์๋๊ฒ์ ํ์ธํ๋ค.
2025-02-25 14:34:04 [hello-app-staging-7985c4d74f-47qnx] INFO com.hellofintech.hellofunding.common.interceptor.ServiceHandlerInterceptor[mergeIntoVisitCount:187] - referer = https://www-stg.hellofunding.co.kr/sp/loan/gtLoan?p=Z29vZ2xlMXN0
ํ์ธ ๊ฒฐ๊ณผ์ด๋ฏธ sendRedirect ๋ก์ง์์๋ Header์ Referer๋ฅผ ๋ฌผ๊ณ ์์๋ค.
์ด๋ ํ referrer๋ฅผ ๊ธฐ์ค์ผ๋ก ์ง๊ณ๋ฅผ ํ๋์ง ์ ํํ ํ์ ์ด ํ์ํ๋ค.