<commit_before>// Define the dependency to page-init in common
define(['jquery', 'jquery-migrate', "page-init"], function($, jqueryMigrate, pageInit) {

    var addGaEventToTaxLink = function() {
        //Tracking events for Tax/SORN interactions
        if ($('#tax_details a').length) {
            var taxLink = $('#tax_details a');
            taxLink.on('click', function() {
                _gaq.push(['_setCustomVar', 1, 'taxsorn', 'tax_through', 3]);
                _gaq.push(['_trackEvent', 'taxsorn', 'tax_through']);
            });
        }
    };

    var addGaEventToManualAddress = function() {
        var enterAddressManually = $('#enterAddressManuallyButton');
        if (enterAddressManually.length) {
            enterAddressManually.on('click', function() {
                _gaq.push(['_trackEvent', "manual_address", "link", "user clicked through manual address", 1]);
            });
        }

        var enterAddressManually = $('#ga-manual-address-submit');
        if (enterAddressManually.length) {
            enterAddressManually.on('click', function() {
                _gaq.push(['_trackEvent', "manual_address", "submit", "user submitted the manual address", 1]);
            });
        }

    };

    var enableSendingGaEventsOnSubmit = function() {
        $('button[type="submit"]').on('click', function(e) {
            //Tracking events for SORN checkbox submit
            var sornInputChecked = $('#sornVehicle').is(':checked');
            if (sornInputChecked) {
                _gaq.push(['_setCustomVar', 1, 'taxsorn', 'sorn', 3]);
                _gaq.push(['_trackEvent', 'taxsorn', 'sorn']);
            }

            // tracking the optional email fields on the trader details page
            if ($('.ga-email-option-visible').is(':checked')) {
                console.log("");
                _gaq.push(['_trackEvent', "optional_field", "trader_email", 'provided']);
            }
            if ($('.ga-email-option-invisible').is(':checked')) {
                _gaq.push(['_trackEvent',  "optional_field", "trader_email", 'absent']);
            }

        });
    };



    return {
        init: function() {
            enableSendingGaEventsOnSubmit();

            // Run the common code that is not common to all but this exemplar needs
            pageInit.hideEmailOnOther('#privatekeeper_title_titleOption_4', '.form-item #privatekeeper_title_titleText');
            pageInit.hideEmailOnOther('#tax', '#tax_details');
            pageInit.hideEmailOnOther('#sorn', '#sorn_details');
            pageInit.hideEmailOnOther('#neither', '#neither_details');

            addGaEventToTaxLink();
            addGaEventToManualAddress();

            // SORN form reset
            $('.sorn-tax-radio-wrapper label input').on('click', function() {
                var targetSorn = $(this).attr('id');
                if (targetSorn != "sorn") {
                    $('#sornVehicle').removeAttr("checked");
                }
            });<commit_msg>US3189: Create Google Analytics Events<commit_after>// Define the dependency to page-init in common
define(['jquery', 'jquery-migrate', "page-init"], function($, jqueryMigrate, pageInit) {

    var addGaEventToTaxLink = function() {
        //Tracking events for Tax/SORN interactions
        if ($('#tax_details a').length) {
            var taxLink = $('#tax_details a');
            taxLink.on('click', function() {
                _gaq.push(['_setCustomVar', 1, 'taxsorn', 'tax_through', 3]);
                _gaq.push(['_trackEvent', 'taxsorn', 'tax_through']);
            });
        }
    };

    var enableSendingGaEventsOnSubmit = function() {
        $('button[type="submit"]').on('click', function(e) {
            //Tracking events for SORN checkbox submit
            var sornInputChecked = $('#sornVehicle').is(':checked');
            if (sornInputChecked) {
                _gaq.push(['_setCustomVar', 1, 'taxsorn', 'sorn', 3]);
                _gaq.push(['_trackEvent', 'taxsorn', 'sorn']);
            }

            // tracking the optional email fields on the trader details page
            trackingOptionalRadioField("#traderEmailOption", "trader_email");
            trackingOptionalRadioField("#privatekeeper_option_email", "private_keeper_email");
            trackingOptionalRadioField("#businesskeeper_option_email", "business_keeper_email");
            trackingOptionalRadioField("#fleetNumberOption", "fleet_number");

            //track driving licence number
            trackingOptionalFields("#privatekeeper_drivernumber", "driving_licence");
            //track mileage
            trackingOptionalFields("#mileage", "mileage");

            //track date of birth
            trackingDateFields("#privatekeeper_dateofbirth", "date_of_birth");

            // track if the new owner is a business or an individual
            trackPrivateBusiness();

        });
    };

    var trackPrivateBusiness = function() {
        if ($("#vehicleSoldTo_Private").is(':checked')) {
            _gaq.push(['_trackEvent', "track_path", "individual", '', value]);
        }
        if ($("#vehicleSoldTo_Business").is(':checked')) {
            _gaq.push(['_trackEvent', "track_path", "business", '', value]);
        }

    };

    // docs here
    var trackingOptionalRadioField = function(fieldSelector, actionName, value) {
        var visibleField = $(fieldSelector + "_visible");
        var invisibleField = $(fieldSelector + "_invisible");

        if (value === undefined) value = 1;

        if (visibleField.is(':checked')) {
            _gaq.push(['_trackEvent', "optional_field", actionName, 'provided', value]);
        }
        if (invisibleField.is(':checked')) {
            _gaq.push(['_trackEvent',  "optional_field", actionName, 'absent', value]);
        }
    };

    var trackingOptionalFields = function(fieldSelector, actionName, value) {
        if (value === undefined) value = 1;

        if($(fieldSelector).value == "") {
            _gaq.push(['_trackEvent', "optional_field", actionName, 'absent', value]);
        } else {
            _gaq.push(['_trackEvent', "optional_field", actionName, 'provided', value]);
        }
    };

    var trackingDateFields = function(fieldSelector, actionName, value) {

        if (value === undefined) value = 1;

        var field_day = $(fieldSelector + "_day");
        var field_month = $(fieldSelector + "_month");
        var field_year = $(fieldSelector + "_year");


        if(field_day.value == "" || field_month.value == "" || field_year.value == "") {
            _gaq.push(['_trackEvent', "optional_field", actionName, 'absent', value]);
        } else {
            _gaq.push(['_trackEvent', "optional_field", actionName, 'provided', value]);
        }
    };


    return {
        init: function() {
            enableSendingGaEventsOnSubmit();

            // Run the common code that is not common to all but this exemplar needs
            pageInit.hideEmailOnOther('#privatekeeper_title_titleOption_4', '.form-item #privatekeeper_title_titleText');
            pageInit.hideEmailOnOther('#tax', '#tax_details');
            pageInit.hideEmailOnOther('#sorn', '#sorn_details');
            pageInit.hideEmailOnOther('#neither', '#neither_details');

            addGaEventToTaxLink();

            // SORN form reset
            $('.sorn-tax-radio-wrapper label input').on('click', function() {
                var targetSorn = $(this).attr('id');
                if (targetSorn != "sorn") {
                    $('#sornVehicle').removeAttr("checked");
                }
            });
{'fraction_non_alphanumeric': 0.1491262646170017, 'fraction_numerical': 0.0024963868085665485, 'mean_word_length': 2.3906458797327392, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4253080', 'n_tokens_mistral': 2128, 'n_tokens_neox': 2029, 'n_words': 426}