<commit_before>(function() {
    function trackTaskCompletion(needID, format) {
        if (format == "guide") {
            trackGuideFormatSuccess(needID);
        }
    }

    function trackFormatEntry(needID, format)
    {
        _gaq.push(['_trackEvent', 'MS_'+format, needID, 'Entry']);
    }

    function trackGuideFormatSuccess(needID)
    {
        var success = { "success": false };
        setTimeout(function() {
            onSuccess(success, needID);
        }, 7000);
        $("#content a").click(function() {
            onSuccess(success, needID);
            if ($(this).data('events').click.length === 1) {
              setTimeout('document.location = "' + $(this).attr("href") + '"', 50)
            }
        });
    }

    function onSuccess(dict, needID) {
        if (dict.success) {
            return;
        }
        dict.success = true;
        _gaq.push(['_trackEvent', 'MS_guide', needID, 'Success']);
    }

    function userCameFromThePageWithinTheSameArtefact() {
        var artefactURL = document.URL.split('/').slice(0,4).join('/');
        return (document.referrer.indexOf(artefactURL) == 0);
    }


    // Track format entry before DOM ready
    var userFromSameArtefact = userCameFromThePageWithinTheSameArtefact();
    if (!userFromSameArtefact) {
        trackFormatEntry(GOVUK.Analytics.NeedID, GOVUK.Analytics.Format);
    }

    // Track format success on DOM ready
    $(function() {
        if (!userFromSameArtefact) {
            trackTaskCompletion(GOVUK.Analytics.NeedID, GOVUK.Analytics.Format);
        }<commit_msg>Add try/catch to handle errors & tidy setTimeout<commit_after>(function() {
    function trackTaskCompletion(needID, format) {
        if (format == "guide") {
            trackGuideFormatSuccess(needID);
        }
    }

    function trackFormatEntry(needID, format)
    {
        _gaq.push(['_trackEvent', 'MS_'+format, needID, 'Entry']);
    }

    function trackGuideFormatSuccess(needID)
    {
        var success = { "success": false };
        setTimeout(function() {
            onSuccess(success, needID);
        }, 7000);
        $("#content a").click(function() {
            onSuccess(success, needID);
            try {
              if ($(this).data('events').click.length === 1) {
                window.setTimeout(function () {
                  document.location = $(this).attr("href");
                }, 50)
              }
            } catch(err) {}
        });
    }

    function onSuccess(dict, needID) {
        if (dict.success) {
            return;
        }
        dict.success = true;
        _gaq.push(['_trackEvent', 'MS_guide', needID, 'Success']);
    }

    function userCameFromThePageWithinTheSameArtefact() {
        var artefactURL = document.URL.split('/').slice(0,4).join('/');
        return (document.referrer.indexOf(artefactURL) == 0);
    }


    // Track format entry before DOM ready
    var userFromSameArtefact = userCameFromThePageWithinTheSameArtefact();
    if (!userFromSameArtefact) {
        trackFormatEntry(GOVUK.Analytics.NeedID, GOVUK.Analytics.Format);
    }

    // Track format success on DOM ready
    $(function() {
        if (!userFromSameArtefact) {
            trackTaskCompletion(GOVUK.Analytics.NeedID, GOVUK.Analytics.Format);
        }
{'fraction_non_alphanumeric': 0.1375114085792516, 'fraction_numerical': 0.0060845756008518406, 'mean_word_length': 2.271641791044776, 'pattern_counts': {'":': 2, '<': 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': '3933904', 'n_tokens_mistral': 992, 'n_tokens_neox': 954, 'n_words': 167}