<commit_before>(function () {

    function getDocument(script) {
        return script ? script.ownerDocument : document;
    }

    function getCurrentScript() {
        var script = window.HTMLImports ? window.HTMLImports.currentScript : undefined;

        if (!script && !!document.currentScript) {
            script = document.currentScript.__importElement || document.currentScript;
        }

        return script;
    }

    var gaScript = getCurrentScript();
    var gaDocument = getDocument(gaScript);
    var serviceUrl = gaScript.getAttribute('serviceurl');
    var trackingId = gaScript.getAttribute('trackingid');
    var pageId = gaScript.getAttribute('pageid');
    var uid = gaDocument.baseURI.split('?uid=')[1].split("&")[0];
    var viewId;
    var dataCharts = [];

// GA API BEGIN

    function queryAccounts() {
        gapi.client.analytics.management.accounts.list().then(handleAccounts);
    }

    function getPropertyUrl(accountId, propertyId) {
        gapi.client.analytics.management.webproperties.get({
            'accountId': accountId,
            'webPropertyId': propertyId
        }).then(function (response) {
            setTitle(response.result.name);
        });
    }

    function handleAccounts(response) {
        // Handles the response from the accounts list method.
        if (response.result.items && response.result.items.length) {
            // Get the first Google Analytics account.
            var firstAccountId = response.result.items[0].id;

            // Uncomment if we need to show url for selected tracking Id
            //getPropertyUrl(firstAccountId, trackingId);

            // Query for properties.
            queryProfiles(firstAccountId, trackingId);
        } else {
            showError('No GA accounts found for the user.');
        }
    }

    function showRequestError(errorObject) {
        if (errorObject.error && errorObject.error.message) {
            showError(errorObject.error.message);
        }
    }

    function queryProfiles(accountId, propertyId) {
        // Get a list of all Views (Profiles) for the first property
        // of the first Account.
        gapi.client.analytics.management.profiles.list({
            'accountId': accountId,
            'webPropertyId': propertyId
        })
            .then(handleProfiles)
            .then(null, function (err) {
                // Log any errors.
                console.log(err);
                showRequestError(err.result);
            });
    }

    function handleProfiles(response) {<commit_msg>Fixed fetching of profiles when there are several GA accounts available<commit_after>(function () {

    function getDocument(script) {
        return script ? script.ownerDocument : document;
    }

    function getCurrentScript() {
        var script = window.HTMLImports ? window.HTMLImports.currentScript : undefined;

        if (!script && !!document.currentScript) {
            script = document.currentScript.__importElement || document.currentScript;
        }

        return script;
    }

    var gaScript = getCurrentScript();
    var gaDocument = getDocument(gaScript);
    var serviceUrl = gaScript.getAttribute('serviceurl');
    var trackingId = gaScript.getAttribute('trackingid');
    var pageId = gaScript.getAttribute('pageid');
    var uid = gaDocument.baseURI.split('?uid=')[1].split("&")[0];
    var viewId;
    var dataCharts = [];

// GA API BEGIN

    function queryAccounts() {
        gapi.client.analytics.management.accounts.list().then(handleAccounts);
    }

    function getPropertyUrl(accountId, propertyId) {
        gapi.client.analytics.management.webproperties.get({
            'accountId': accountId,
            'webPropertyId': propertyId
        }).then(function (response) {
            setTitle(response.result.name);
        });
    }

    function handleAccounts(response) {
        // Handles the response from the accounts list method.
        if (response.result.items && response.result.items.length) {
            // Get the first Google Analytics account.
            let items = response.result.items.filter(item => (trackingId.indexOf(item.id) > -1));
            var accountId = items[0].id;

            // Uncomment if we need to show url for selected tracking Id
            //getPropertyUrl(firstAccountId, trackingId);

            // Query for properties.
            queryProfiles(accountId, trackingId);
        } else {
            showError('No GA accounts found for the user.');
        }
    }

    function showRequestError(errorObject) {
        if (errorObject.error && errorObject.error.message) {
            showError(errorObject.error.message);
        }
    }

    function queryProfiles(accountId, propertyId) {
        // Get a list of all Views (Profiles) for the first property
        // of the first Account.
        gapi.client.analytics.management.profiles.list({
            'accountId': accountId,
            'webPropertyId': propertyId
        })
            .then(handleProfiles)
            .then(null, function (err) {
                // Log any errors.
                console.log(err);
                showRequestError(err.result);
            });
    }

    function handleProfiles(response) {
{'fraction_non_alphanumeric': 0.10651676829268293, 'fraction_numerical': 0.0013338414634146342, 'mean_word_length': 2.254184748915065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2763759', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1352, 'n_words': 313}