<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <link rel="icon" href="https://assets.googleplaystore.in/asc/I8EVZX7/output_id/static/images/master-icon.png" type="image/gif" sizes="16x16"
          alt="Teen Patti Master">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta http-equiv="x-ua-compatible" content="IE=edge">
    <title>Teen Patti Master</title>
    <meta name="keyword" content="Teen Patti Master">
    <meta name="description" content="Teen Patti Master.!">
    <link href="https://assets.googleplaystore.in/asc/I8EVZX7/output_id/static/css/index.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" href="https://assets.googleplaystore.in/asc/I8EVZX7/output_id/static/css/style.css">
    <link rel="stylesheet" href="https://assets.googleplaystore.in/asc/I8EVZX7/output_id/static/css/swiper.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.4.2/js/swiper.min.js"></script>
    <script src="https://assets.googleplaystore.in/asc/I8EVZX7/output_id/static/js/pub_rem.js" type="text/javascript"></script>
    <script type="text/javascript" src="https://assets.googleplaystore.in/asc/I8EVZX7/output_id/static/js/download.js"></script>

    <!-- Google tag (gtag.js) dynamically loaded with Thymeleaf -->
    <script src="https://www.googletagmanager.com/gtag/js?id=G-T4BRN0HQPV" async></script>

    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());

        gtag('config', "G-T4BRN0HQPV");
    </script>

    <!-- Facebook Pixel dynamically loaded with Thymeleaf -->
    <script>
        /*<![CDATA[*/
        !function (f, b, e, v, n, t, s) {
            if (f.fbq) return;
            n = f.fbq = function () {
                n.callMethod ?
                    n.callMethod.apply(n, arguments) : n.queue.push(arguments)
            };
            if (!f._fbq) f._fbq = n;
            n.push = n;
            n.loaded = !0;
            n.version = '2.0';
            n.queue = [];
            t = b.createElement(e);
            t.async = !0;
            t.src = v;
            s = b.getElementsByTagName(e)[0];
            s.parentNode.insertBefore(t, s)
        }(window, document, 'script',
            'https://connect.facebook.net/en_US/fbevents.js');
        fbq('init', "929585772303790");
        fbq('track', 'PageView');
        /*]]>*/
    </script>

    <noscript><img height="1" width="1" style="display:none"
                   src="https://www.facebook.com/tr?id=929585772303790&amp;ev=PageView&amp;noscript=1"/></noscript>
    <!-- End Facebook Pixel Code -->
</head>

<body>
<div class="container">
    <div id="top" onClick="download('download_top')"></div>
    <a href="javascript:void(0);"><img class="bg" src="https://assets.googleplaystore.in/asc/I8EVZX7/output_id/static/images/page-bg.jpg" alt="Teen Patti Master"></a>
    <div class="kefu">
        <a href="javascript:download('download_kefu')">
            <img src="https://assets.googleplaystore.in/asc/I8EVZX7/output_id/static/images/btn_advisory.png" alt="Teen Patti Master">
        </a>
    </div>
    <div class="downBtn" onClick="download('download_button')">
        <img src="https://assets.googleplaystore.in/asc/I8EVZX7/output_id/static/images/btn_download.png" alt="Teen Patti Master">
    </div>
    <div class="downNum">
        <img src="https://assets.googleplaystore.in/asc/I8EVZX7/output_id/static/images/downNum.png" style="width: 100%;" alt="">
    </div>
    <div class="bannerBox">
        <div class="banner">
            <div class="swiper-wrapper">
                <div class="swiper-slide"><img src="https://assets.googleplaystore.in/asc/I8EVZX7/output_id/static/images/ad_01.png" alt="Teen Patti Master"/></div>
                <div class="swiper-slide"><img src="https://assets.googleplaystore.in/asc/I8EVZX7/output_id/static/images/ad_02.jpg" alt="Teen Patti Master"/></div>
            </div>
        </div>
    </div>

    <div class="footer">
        <p>Copyright 2022 Teen Patti Master All
            Rights Reseved </p>
    </div>

    <script>
        $(function () {
            var mySwiper = new Swiper('.banner', {
                slidesPerView: 1,
                visibilityFullFit: true,
                autoplay: 3000,
                loop: true,
            });
        });
    </script>
</div>

<input type="hidden" id="channel" value="slm_1200505" />
<input type="hidden" id="appName" value="Teen Patti Master" />
<input type="hidden" id="pkgType" value="1" />
<input type="hidden" id="downloadDomain" value="https://d18zyr2hf32ul9.cloudfront.net" />
<input type="hidden" id="adjustTrackerToken" value="1cfm4poc" />
<input type="hidden" id="onlinePkgUrl" value="" />
<input type="hidden" id="ext" value="" />
<input type="hidden" id="pixelId" value="929585772303790" />
<input type="hidden" id="eventId" value="64723731-7f6d-45b0-be26-1e6ca51cfae9" />

<script>
    var fbp = getCookie('_fbp') || getQueryString('_fbp') || getQueryString("fbp") || getCookie('fbp');
    var fbc = getCookie('_fbc') || getQueryString('_fbc') || getQueryString("fbc") || getCookie('fbc');
    console.log('fbp', fbp)
    console.log('fbc', fbc)

    let pkgType = document.getElementById('pkgType').value;
    let downloadDomain = document.getElementById('downloadDomain').value;
    let adjustTracker = document.getElementById('adjustTrackerToken').value;
    let onlinePkgUrl = document.getElementById('onlinePkgUrl').value;
    let ext = document.getElementById('ext').value;
    let pxid = document.getElementById('pixelId').value;
    let appName = document.getElementById('appName').value;
    let channel = document.getElementById('channel').value;
    let eventId = document.getElementById('eventId').value;

    let extStr = JSON.stringify(ext)
    let encodeExtStr = encodeURIComponent(extStr)
    let offlineUrl;
    let url = '';

    let reportFlag = 0

    // 开始计时
    const startTime = Date.now();

    function checkCookie() {
        const startTime = Date.now(); // 记录开始时间
        let timeCost = 0; // 保存时间花费

        const intervalId = setInterval(() => {
            const fbcValue = getCookie('_fbc');
            const currentTime = Date.now();
            if (fbcValue) {
                // 停止监听
                clearInterval(intervalId);

                // 计算时间花费
                timeCost = currentTime - startTime;
                reportLog(timeCost);
                // 在控制台输出时间花费
                console.log('Time cost:', timeCost, 'milliseconds');
            } else if (currentTime - startTime > 10000) {
                // 超过10秒仍未找到_fbc，打印日志
                clearInterval(intervalId);
                timeCost = currentTime - startTime;
                reportLog(timeCost);
                console.log('Time cost exceeds 10 seconds. _fbc not found.');
            } else {
                console.log('Check Cookie: _fbc not found yet.');
            }
        }, 100); // 间隔0.1秒检查一次
        checkFbc(intervalId,startTime,timeCost)
    }

    function checkFbc(intervalId,starTime,timeCost) {
        console.log('checkFbc')
        const fbcValue = getCookie('_fbc');
        const currentTime = Date.now();
        if (fbcValue) {
            // 停止监听
            clearInterval(intervalId);

            // 计算时间花费
            timeCost = currentTime - startTime;
            reportLog(timeCost);
            // 在控制台输出时间花费
            console.log('Time cost:', timeCost, 'milliseconds');
        } else if (currentTime - startTime > 10000) {
            // 超过10秒仍未找到_fbc，打印日志
            clearInterval(intervalId);
            timeCost = currentTime - startTime;
            reportLog(timeCost);
            console.log('Time cost exceeds 10 seconds. _fbc not found.');
        } else {
            console.log('Check Cookie: _fbc not found yet.');
        }
    }

    // 调用函数开始监听
    checkCookie();

    //读取url参数
    const urlParams = new Proxy({}, {
        get: (target, name) => name in target ? target[name] : ''
    });

    window.addEventListener("DOMContentLoaded", () => {
        const currentURL = window.location.href;
        const parsedURL = new URL(currentURL);
        const params = parsedURL.searchParams;
        for (const [param, value] of params) {
            urlParams[param] = value;
        }
    });
    console.log(urlParams)

    var gclid = getGclid();
    console.log('getGclid:', gclid)
    function getGclid() {
        let ups = readUrlParams();
        if(ups.gclid) {
            return ups.gclid
        }
        let adjust_referrer = ups.adjust_referrer
        if(adjust_referrer) {
            adjust_referrer = decodeURIComponent(adjust_referrer)
            let ar = adjust_referrer.split("=")
            console.log('ar:', ar)
            if(ar && ar.length > 1) {
                return ar[1]
            }
        }
        return ''
    }
    var wbraid = getQueryString("wbraid") || getCookie('wbraid');
    var gbraid = getQueryString("gbraid") || getCookie('gbraid');

    function getQueryString(name) {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        }
        return "";
    }

    function getCookie(cname) {
        let name = cname + "=";
        let ca = document.cookie.split(';');
        for (let i = 0; i < ca.length; i++) {
            let c = ca[i];
            while (c.charAt(0) == ' ') {
                c = c.substring(1);
            }
            if (c.indexOf(name) == 0) {
                return c.substring(name.length, c.length);
            }
        }
        return "";
    }

    function createEventId() {
        return 'xxxxxxxyx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
            var r = Math.random() * 16 | 0,
                v = c === 'x' ? r : (r & 0x3 | 0x8);
            return v.toString(16);
        });
    }

    //线下包地址
    if(pkgType === '1') {
        offlineUrl = downloadDomain + '/cg/gaoct/fg/' + appName + '.apk?' + 'channel=' + channel + '&pxid=' + pxid + '&fbp=' + fbp + '&fbc=' + fbc + '&gclid=' + gclid + '&wbraid=' + wbraid + '&gbraid=' + gbraid + '&eventId=' + eventId + '&ext=' + encodeExtStr;

        console.log('offlineUrl:', offlineUrl)
        url = offlineUrl;
    } else if(pkgType === '2') {
        //线上包地址
        url = buildOnlinePkgReferrer()
    }

    webClick()
    function webClick() {

        let uri = window.location.href;
        uri = uri.replace(/^https?:\/\//, '');
        uri = encodeURIComponent(uri)
        // 获取当前页面的所有 Cookie
        const cookies = document.cookie;
        let logrpUrl = '';

        const urlP = readUrlParams()

        if (isGoogleAdLink()) {
            const campaignName = urlP.campaign
            const adset = urlP.adgroup
            const creative = urlP.creative
            const gbraid = urlP.gbraid
            const wbraid = urlP.wbraid
            logrpUrl = 'https://tracker2.bx1.pw/webAdsTracker/click?uri=' + uri + '&eventId=' + eventId + '&channel=' + channel +
                '&gbraid=' + gbraid + '&wbraid=' + wbraid + '&campaignName=' + campaignName + "&campaignId=" + campaignName + '&gclid=' + gclid + '&adsetName=' + adset + '&adsetId=' + adset + '&creative='
                + creative + '&adjustTrackerToken=' + adjustTracker
        } else if (isFacebookAdLink()) {
            const campaignName = urlP.p1
            const campaignId = urlP.p2
            const adsetName = urlP.p3
            const adsetId = urlP.p4
            const adName = urlP.p5
            const adId = urlP.p6
            const fbclid = urlP.fbclid
            const fbpid = urlP.fbpid
            logrpUrl = 'https://tracker2.bx1.pw/webAdsTracker/click?uri=' + uri + '&eventId=' + eventId + '&channel=' + channel +
                '&campaignName=' + campaignName + '&adsetName=' + adsetName + '&adjustTrackerToken=' + adjustTracker +
                '&campaignId=' + campaignId + '&adsetId=' + adsetId + '&adName=' + adName + '&adId=' + adId + '&fbclid=' + fbclid + '&fbpid=' + fbpid;
        } else {
            //自然量
            logrpUrl = 'https://tracker2.bx1.pw/webAdsTracker/click?uri=' + uri + '&eventId=' + eventId + '&channel=' + channel +
                '&adjustTrackerToken=' + adjustTracker
        }

        // 发送GET请求
        fetch(logrpUrl,{mode:'no-cors'})
            .then(response => {
            })
            .then(data => {
            })
            .catch(error => {
                console.log('web click error', error)
            });
    }

    function onBtnClick(redirect) {

        if (isGoogleAdLink()) {
            const campaign = urlParams.campaign
            const adgroup = urlParams.adgroup
            const creative = urlParams.creative
            const gbraid = urlParams.gbraid
            const wbraid = urlParams.wbraid
            const url = 'https://app.adjust.com/' + adjustTracker + '?engagement_type=fallback_click&campaign=' + campaign + '&external_click_id=' + gclid +
                '&adgroup=' + adgroup + '&creative=' + creative + '&gbraid=' + gbraid + '&wbraid=' + wbraid + '&redirect=' + redirect
            console.log(url)
            window.location.href = url;
        } else if (isFacebookAdLink()) {
            const campaignName = urlParams.p1
            const campaignId = urlParams.p2
            const adsetName = urlParams.p3
            const adsetId = urlParams.p4
            const adName = urlParams.p5
            const adId = urlParams.p6
            const fbclid = urlParams.fbclid
            const fbpid = urlParams.fbpid
            const url = 'https://app.adjust.com/' + adjustTracker + '?engagement_type=fallback_click&campaign=' + campaignName + '%20%28' + campaignId
                + '%29&adgroup=' + adsetName + '%20%28' + adsetId + '%29&creative=' + adName + '%20%28' + adId + '%29&fbclid='
                + fbclid + '&fbpid=' + fbpid + '&redirect=' + redirect
            window.location.href = url;
        } else {
            window.location.href = 'https://app.adjust.com/' + adjustTracker + '?engagement_type=fallback_click&redirect=' + redirect;
        }
    }

    function isGoogleAdLink() {
        return gclid
    }

    function isFacebookAdLink() {
        return window.location.href.includes('fbclid');
    }

    function sendGtagEvent(action) {
        console.log('sendGtagEvent', action)
        // 其他参数被设定为固定值
        const category = 'button';
        const label = 'myButton';
        const value = 1;

        gtag('event', action, {
            'event_category': category,
            'event_label': label,
            'value': value
        });
    }

    //必须将download赋值给window
    function download(eventName) {
        sendGtagEvent(eventName)
        reportLog(Date.now() - startTime);
        var encodedUrl = encodeURIComponent(url);
        onBtnClick(encodedUrl);
    }

    window.download = download;

    function readUrlParams() {
        //读取url参数
        const urlParams = new Proxy({}, {
            get: (target, name) => name in target ? target[name] : ''
        });

        const currentURL = window.location.href;
        const parsedURL = new URL(currentURL);
        const params = parsedURL.searchParams;

        for (const [param, value] of params) {
            urlParams[param] = value;
            console.log('urlParams: ', urlParams[param])
        }
        return urlParams;
    }

    function reportLog(timeCost) {
        if(reportFlag > 0) {
            return;
        }
        reportFlag = 1
        let uri = window.location.href;
        uri = uri.replace(/^https?:\/\//, '');
        console.log('uri:', uri)
        // 获取当前页面的所有 Cookie
        const cookies = document.cookie;
        // 将 Cookie 添加到 URL 参数中
        let cookieA = `&cookie=${encodeURIComponent(cookies)}`;
        let logrpUrl = '';

        const urlP = readUrlParams()

        var uriWithoutParams = window.location.origin + window.location.pathname;
        const p0 = urlP.p0
        const p1 = urlP.p1
        const p2 = urlP.p2
        const p3 = urlP.p3
        const p4 = urlP.p4
        const p5 = urlP.p5
        const p6 = urlP.p6
        const fbclid = urlP.fbclid

        logrpUrl = 'https://tracker2.bx1.pw/webAdsTracker/report?uri=' + uriWithoutParams + '&p0=' + p0 + '&p1=' + p1 + '&p2=' + p2 + '&p3=' + p3 + '&p4=' + p4
            + '&p5=' + p5 + '&p6=' + p6 + '&fbclid=' + fbclid + '&eventId=' + eventId + cookieA + '&timecost=' + timeCost + '&channel=' + channel;
        // 发送GET请求
        fetch(logrpUrl,{mode:'no-cors'})
            .then(response => {
                if (!response.ok) {
                    throw new Error(`HTTP error! Status: ${response.status}`);
                }
                return response.json();
            })
            .then(data => {
                console.log('reportLog', logrpUrl)
            })
            .catch(error => {
                console.log('reportLog:', logrpUrl)
            });
    }

    function hasQuestionMark(uri) {
        const regex = /\?/;
        return regex.test(uri);
    }

    function buildOnlinePkgReferrer() {
        let up = readUrlParams()
        if (isFacebookAdLink()) {
            onlinePkgUrl = onlinePkgUrl + '&referrer=fbclid%3D' + up.fbclid + '%26eventId%3D' + eventId
        } else if (isGoogleAdLink()) {
            onlinePkgUrl = onlinePkgUrl + '&referrer=fbclid%3D' + gclid + '%26eventId%3D' + eventId
        } else {
            onlinePkgUrl = onlinePkgUrl + '&referrer=eventId%3D' + eventId
        }
        return onlinePkgUrl
    }
</script>

<script>
    const scrCode = 'I8EVZX7'
</script>
</body>

</html>