﻿function newRegistrationEventPixel() {
        window.dotq = window.dotq || [];
        window.dotq.push(
        {
            'projectId': '10000',
            'properties': {
                'pixelId': '436168',
                'qstrings': {
                    'et': 'custom',
                    'el': 'CreatedAccount'
                }
            }
        });
}

function initialPayment() { 
    window.dotq = window.dotq || [];
    window.dotq.push(
    {
        'projectId': '10000',
        'properties': {
            'pixelId': '436168',
            'qstrings': {
                'et': 'custom',
                'el': 'Payment'
            }
        }
    });
    //Begin TVSquared Tracking Code
    var cookieValue = getCookie("User_Info");
    var myUserArray = cookieValue.split("&");
    var userId = myUserArray[0].substring(myUserArray[0].indexOf("=")+1);
    var revenueValue = myUserArray[1].substring(myUserArray[1].indexOf("=") + 1);
    var prodValue = myUserArray[2].substring(myUserArray[2].indexOf("=") + 1);    
    var actionValue = myUserArray[3].substring(myUserArray[3].indexOf("=") + 1);
    var Promocode = myUserArray[4].substring(myUserArray[4].indexOf("=") + 1);
    
    var _tvq = window._tvq = window._tvq || [];
    
        var session = {
            'user': userId
        };
        var actionname = 'Initial';
        var action = {
            'rev': revenueValue,
            'prod': prodValue,
            'id': actionValue,
            'promo': Promocode
        };

        var u = (("https:" == document.location.protocol) ? "https://collector-3203.tvsquared.com/" : "http://collector-3203.tvsquared.com/");
        _tvq.push(['setSiteId', "TV-63729063-1"]);
        _tvq.push(['setTrackerUrl', u + 'tv2track.php']);
        _tvq.push([function () {
            this.setCustomVariable(5, 'session', JSON2.stringify(session), 'visit')
        }]);
        _tvq.push([function () {
            this.setCustomVariable(5, actionname, JSON2.stringify(action), 'page')
        }]);
        _tvq.push(['trackPageView']);
        var d = document,
            g = d.createElement('script'),
            s = d.getElementsByTagName('script')[0];
        g.type = 'text/javascript';
        g.defer = true;
        g.async = true;
        g.src = u + 'tv2track.js';
        s.parentNode.insertBefore(g, s);
    //End TVSquared Tracking Code
}

function getCookie(name) {
    var nameEquals = name + "=";
    var whole_cookie = document.cookie.split(nameEquals)[1]?.split(";")[0];
    return whole_cookie;
}

function instalmentPayment() {   

    window.dotq = window.dotq || [];
    window.dotq.push(
    {
        'projectId': '10000',
        'properties': {
            'pixelId': '436168',
            'qstrings': {
                'et': 'custom',
                'el': 'InstalmentPayment'
            }
        }
    });
}


function finalPayment() {  

    window.dotq = window.dotq || [];
    window.dotq.push(
    {
        'projectId': '10000',
        'properties': {
            'pixelId': '436168',
            'qstrings': {
                'et': 'custom',
                'el': 'FinalPayment'
            }
        }
    });   
    //Begin TVSquared Tracking Code
    var cookieValue = getCookie("User_Info");
    var myUserArray = cookieValue.split("&");
    var userId = myUserArray[0].substring(myUserArray[0].indexOf("=") + 1);
    var revenueValue = myUserArray[1].substring(myUserArray[1].indexOf("=") + 1);
    var prodValue = myUserArray[2].substring(myUserArray[2].indexOf("=") + 1);
    var actionValue = myUserArray[3].substring(myUserArray[3].indexOf("=") + 1);
    var Promocode = myUserArray[4].substring(myUserArray[4].indexOf("=") + 1);
    
    var _tvq = window._tvq = window._tvq || [];    
        var session = {
            'user': userId
        };
        var actionname = 'Final';
        var action = {
            'rev': revenueValue,
            'prod': prodValue,
            'id': actionValue,
            'promo': Promocode
        };

        var u = (("https:" == document.location.protocol) ? "https://collector-3203.tvsquared.com/" : "http://collector-3203.tvsquared.com/");
        _tvq.push(['setSiteId', "TV-63729063-1"]);
        _tvq.push(['setTrackerUrl', u + 'tv2track.php']);
        _tvq.push([function () {
            this.setCustomVariable(5, 'session', JSON2.stringify(session), 'visit')
        }]);
        _tvq.push([function () {
            this.setCustomVariable(5, actionname, JSON2.stringify(action), 'page')
        }]);
        _tvq.push(['trackPageView']);
        var d = document,
            g = d.createElement('script'),
            s = d.getElementsByTagName('script')[0];
        g.type = 'text/javascript';
        g.defer = true;
        g.async = true;
        g.src = u + 'tv2track.js';
        s.parentNode.insertBefore(g, s);
    //End TVSquared Tracking Code
}

function downloadBrochureEventPixel() {    
        window.dotq = window.dotq || [];
        window.dotq.push(
        {
            'projectId': '10000',
            'properties': {
                'pixelId': '436168',
                'qstrings': {
                    'et': 'custom',
                    'el': 'Downloaded'
                }
            }
        });
}

function newRegistrationEventTVAttributionPixel(AccID,PlanID)
{
    var _tvq = window._tvq = window._tvq || [];

    (function () {

        var session = {

            'user': AccID

        };

        var actionname = 'accountcreate';

        var action = {

            'rev': 'N/A',

            'prod': 'N/A',

            'id': PlanID,

            'promo': 'N/A'

        };

        var u = (("https:" == document.location.protocol) ? "https://collector-3203.tvsquared.com/" : "http://collector-3203.tvsquared.com/");

        _tvq.push(['setSiteId', "TV-63729063-1"]);

        _tvq.push(['setTrackerUrl', u + 'tv2track.php']);

        _tvq.push([function () {

            this.setCustomVariable(5, 'session', JSON2.stringify(session), 'visit')

        }]);

        _tvq.push([function () {

            this.setCustomVariable(5, actionname, JSON2.stringify(action), 'page')

        }]);

        _tvq.push(['trackPageView']);

        var d = document,

            g = d.createElement('script'),

            s = d.getElementsByTagName('script')[0];

        g.type = 'text/javascript';

        g.defer = true;

        g.async = true;

        g.src = u + 'tv2track.js';

        s.parentNode.insertBefore(g, s);

    })();

  ga('send', 'event', 'accountcreate', 'accountcreate', 'na', 43);

}

// COF-4917
function newRegistrationEventGA4(EmailAddress, PhoneNumber, FirstName, LastName) {
    var cookieValue = getCookie("AffiliateID");
    gtag('event', 'account_created', {
        user_data: {
            email_address: EmailAddress,
            phone_number: PhoneNumber,
            AffiliateID: cookieValue,
            address: {
                first_name: FirstName,
                last_name: LastName
            }
        }
    });
}

// COF-4928
function newChatEventGA4() {    
    var cookieValue = getCookie("AffiliateID");
    gtag('event', 'chat_initiated', { AffiliateID: cookieValue });    
}

// COF-4926
function newPurchaseEventGA4(amount, paymentType) {
    var cookieValue = getCookie("AffiliateID");    
    gtag('event', 'purchase', { currency: 'USD', value: amount, purchasePaymentType: paymentType, AffiliateID: cookieValue });
  
}

// COF-4927
function newProductAddedGA4(productName, productPrice) {
    var cookieValue = getCookie("AffiliateID");   
    gtag('event', 'product_added', { productAddedName: productName, productAddedPrice: productPrice, AffiliateID: cookieValue });
    
}

// COF-4927
function newContactGA4() {
    var cookieValue = getCookie("AffiliateID");
    gtag('event', 'contact_us', { AffiliateID: cookieValue });
}

// COF-5100
function newTimeslotSelectionGA4(package, venue, date, customerID) {
    if (package === undefined || package === null) package = '';
    package = package.replace("&#39;", "'");

    if (venue === undefined || venue === null) venue = '';
    venue = venue.replace("&#39;", "'");

    if (date === undefined || date === null) date = -1;
    if (customerID === undefined || customerID === null) customerID = -1;
    var cookieValue = getCookie("AffiliateID");
    gtag('event', 'timeslot_selection', { timeslotPackage: package, timeslotVenue: venue, timeslotDate: date, timeslotCustomerID: customerID, AffiliateID: cookieValue });   
}

// COF-5165
function newCongratulationsVideoGA4(location) {
    var cookieValue = getCookie("AffiliateID");
    gtag('event', 'guest_video_click', { AffiliateID: cookieValue, Location: location });
}

function submitEventPixel() {   
        window.dotq = window.dotq || [];
        window.dotq.push(
        {
            'projectId': '10000',
            'properties': {
                'pixelId': '436168',
                'qstrings': {
                    'et': 'custom',
                    'el': 'ContactedUs'
                }
            }
        });    
}

////function submitTVAttributionPixels() {
////    var _tvq = window._tvq = window._tvq || [];
////    (function () {
////        var session = {
////            'user': '<USERREF>'
////        };
////        var actionname = 'initialPayment';
////        var action = {
////            'rev': ' ',
////            'prod': '',
////            'id': '',
////            'promo': ''
////        };

////        var u = (("https:" == document.location.protocol) ? "https://collector-3203.tvsquared.com/" : "http://collector-3203.tvsquared.com/");
////        _tvq.push(['setSiteId', "TV-63729063-1"]);
////        _tvq.push(['setTrackerUrl', u + 'tv2track.php']);
////        _tvq.push([function () {
////            this.setCustomVariable(5, 'session', JSON2.stringify(session), 'visit')
////        }]);
////        _tvq.push([function () {
////            this.setCustomVariable(5, actionname, JSON2.stringify(action), 'page')
////        }]);
////        _tvq.push(['trackPageView']);
////        var d = document,
////            g = d.createElement('script'),
////            s = d.getElementsByTagName('script')[0];
////        g.type = 'text/javascript';
////        g.defer = true;
////        g.async = true;
////        g.src = u + 'tv2track.js';
////        s.parentNode.insertBefore(g, s);
////    })();
////}







