generated from ttipo/project-base
e91f7620a3
- imweb-header-top.html·imweb-header.html: 아임웹에 실제로 들어가 있는 Header Code 원본을 저장소에 둔다 - 업체 링크 추적을 imweb-header-top.html 의 UTM 스크립트 아래로 옮기고 partner-ref.html 은 삭제 (UTM 스크립트처럼 localStorage + .moneyguider.co.kr 쿠키에 저장 — www ↔ apex 이동·인앱브라우저 대비) - 신청 완료 위젯: MG_UTM.peek() 는 객체라 문자열 검사에 걸려 유입정보가 빠지고 있었다 — peek().value 를 보낸다 - 단축 링크 리다이렉트에 Referrer-Policy strict-origin-when-cross-origin (helmet 기본 no-referrer 때문에 업체가 링크를 올린 곳이 지워져 유입원이 direct 로 잡혔다) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
1.8 KiB
HTML
48 lines
1.8 KiB
HTML
<script>
|
|
//UTM 트래킹을 위한 코드 (무료강의 랜딩용)
|
|
document.addEventListener('mousedown', function(e) {
|
|
// 클릭한 요소가 로그인 링크인지 확인
|
|
const anchor = e.target.closest('a[href*="/login"]');
|
|
|
|
if (anchor) {
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
const utms = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term'];
|
|
|
|
// 1. 현재 주소창에서 UTM 파라미터들 추출
|
|
let foundUtmParams = [];
|
|
utms.forEach(key => {
|
|
if (urlParams.has(key)) {
|
|
foundUtmParams.push(key + '=' + encodeURIComponent(urlParams.get(key)));
|
|
}
|
|
});
|
|
|
|
// UTM이 있을 때만 실행
|
|
if (foundUtmParams.length > 0) {
|
|
const url = new URL(anchor.href, window.location.origin);
|
|
let backUrl = url.searchParams.get('back_url');
|
|
|
|
if (backUrl) {
|
|
try {
|
|
// 2. 기존의 암호화된 back_url을 복호화 (예: /shop_view?idx=38&metaconversion=true)
|
|
let decodedBackUrl = atob(backUrl);
|
|
|
|
// 아임웹이 이미 UTM을 넣어둔 경우(또는 앞선 mousedown에서 넣은 경우) 중복으로 붙이지 않음
|
|
if (/[?&]utm_/.test(decodedBackUrl)) return;
|
|
|
|
// 3. 복호화된 주소 뒤에 UTM 결합
|
|
const separator = decodedBackUrl.includes('?') ? '&' : '?';
|
|
let updatedBackUrl = decodedBackUrl + separator + foundUtmParams.join('&');
|
|
|
|
// 4. 다시 Base64로 암호화해서 back_url 파라미터 교체
|
|
url.searchParams.set('back_url', btoa(updatedBackUrl));
|
|
anchor.href = url.toString();
|
|
|
|
console.log('UTM이 back_url 내부로 성공적으로 삽입되었습니다.');
|
|
} catch (err) {
|
|
console.error('Base64 디코딩/인코딩 오류:', err);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}, true);
|
|
</script> |