Jvascript 카페24 플렛폼 구현
페이지 정보

본문
class Platform {
constructor() {
this.host = "atemshop.com"
this.queryKey = 'utm_term'
this.cookieKey = 'main'
this.main = {
atem: { url: "/", platform: "ATEM" },
labnosh: { url: "/labnosh.html", platform: "LABNOSH" },
}
this.urlSerch = new URLSearchParams(location.search)
const UtmParam = this.getQueryValue(this.queryKey)
this.urlObj = {
"queryValue": UtmParam,
"hasUtm": this.checkUtmTerm(UtmParam),
"checkUtm": false,
"checkReferer": this.checkReferer(this.host)
}
this.platform = "ATEM"
this.platformReady = new Promise((resolve) => {
this.getUtmKeywordList().then(data => {
console.log(data);
this.urlObj.checkUtm = this.checkUtmValue(UtmParam, data);
this.setPlatform();
resolve(); // setPlatform이 끝났다는 것을 알림
});
});
//메인일때
}
setHeader() {
return
this.platformReady.then(() => { // setPlatform이 끝날 때까지 기다림
if (this.platform == "LABNOSH") {
$('#logo_inner').hide();
$('.labnosh_header').show();
}
});
}
checkReferer(host) {
return document.referrer.indexOf(host) !== -1
}
getQueryValue(key) {
return this.urlSerch.get(key) || ''
}
checkUtmTerm(UtmParam) {
return UtmParam ? true : false;
}
checkUtmValue(UtmParam, list) {
return list.some(keyword => UtmParam.indexOf(keyword) !== -1);
}
checkCookie(cookieKey) {
let cookie_value = $.cookie(cookieKey);
return cookie_value ? cookie_value : false;
}
setCookie(cookieKey, cookieValue) {
$.cookie(cookieKey, cookieValue, { path: '/', expires: 7 })
}
setMain(cookieKey, cookieValue, platform) {
this.setCookie(cookieKey, cookieValue)
this.platform = platform
}
async getUtmKeywordList() {
const getJsonData = {}
const ajax_url = '/json/Utmset.json?v='+new Date();
return await new Promise(resolve => {
$.getJSON(ajax_url, getJsonData, function (data) {
console.log(data);
resolve(data)
})
})
}
setPlatform() {
if (this.urlObj.hasUtm && this.urlObj.checkUtm) {
this.setMain(this.cookieKey, this.main.labnosh.url, this.main.labnosh.platform)
} else if (this.urlObj.hasUtm && !this.urlObj.checkUtm) {
this.setMain(this.cookieKey, this.main.atem.url, this.main.atem.platform)
} else if (!this.urlObj.hasUtm) {
//새로운 유입일경우 쿠키를 무조건 atem으로 초기화
if (!this.urlObj.checkReferer) {
this.setMain(this.cookieKey, this.main.atem.url, this.main.atem.platform)
//레퍼럴 있으면 유지
} else {
var url = $.cookie(this.cookieKey);
var platform = url == '/' ? 'ATEM' : 'LABNOSH'
this.setMain(this.cookieKey, url, platform)
}
}
if (location.pathname == '/' || location.pathname == '/index.html') {
//링크를 직접치고들어온경우 레퍼럴이없어 ATEM으로 초기화된다.
if (document.referrer) {
var refererObj = new URL(document.referrer)
if (refererObj.pathname !== '/' && refererObj.pathname !== '/index.html') {
location.href = ($.cookie(this.cookieKey) + location.search) || '/'
}
}
} else if (location.pathname == '/labnosh.html') {
//this.platform = this.main.labnosh.platform
this.setMain(this.cookieKey, this.main.labnosh.url, this.main.labnosh.platform)
}
}
}
const platform = new Platform()
- 이전글getUrlParam 24.04.08
- 다음글background-color-changer 24.03.27
댓글목록
등록된 댓글이 없습니다.