카페24 플렛폼 구현 > 코드모음

본문 바로가기
사이트 내 전체검색

코드모음

Jvascript 카페24 플렛폼 구현

페이지 정보

profile_image
작성자 최고관리자
댓글 0건 조회 1,779회 작성일 24-04-01 14:48

본문

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()

댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입

사이트 정보

회사명 : 회사명 / 대표 : 대표자명
주소 : OO도 OO시 OO구 OO동 123-45
사업자 등록번호 : 123-45-67890
전화 : 02-123-4567 팩스 : 02-123-4568
통신판매업신고번호 : 제 OO구 - 123호
개인정보관리책임자 : 정보책임자명

공지사항

  • 게시물이 없습니다.

접속자집계

오늘
5
어제
38
최대
544
전체
16,561
Copyright © Ideashift.shop. All rights reserved.