<commit_before>/*global ga*/

import MetabaseSettings from "metabase/lib/settings";


// Simple module for in-app analytics.  Currently sends data to GA but could be extended to anything else.
const MetabaseAnalytics = {
    // track a pageview (a.k.a. route change)
    trackPageView: function(url) {
        if (url) {
            // scrub query builder urls to remove serialized json queries from path
            url = (url.lastIndexOf('/q/', 0) === 0) ? '/q/' : url;

            const { tag } = MetabaseSettings.get('version');

            ga('set', 'dimension1', tag);
            ga('set', 'page', url);
            ga('send', 'pageview', url);
        }
    },

    // track an event
    trackEvent: function(category, action, label, value) {
        const { tag } = MetabaseSettings.get('version');

        // category & action are required, rest are optional
        if (category && action) {
            ga('set', 'dimension1', tag);
            ga('send', 'event', category, action, label, value);
        }
    }
}

export default MetabaseAnalytics;


export function registerAnalyticsClickListener() {
    document.body.addEventListener("click", function(e) {
        var node = e.target;

        // check the target and all parent elements
        while (node) {
            if (node.dataset && node.dataset.metabaseEvent) {
                // we expect our event to be a semicolon delimited string
                const parts = node.dataset.metabaseEvent.split(";");
                MetabaseAnalytics.trackEvent(...parts);
            }
            node = node.parentNode;
        }
    }, true);
}<commit_msg>add a little trimming to protect against stray spaces in our event names.<commit_after>/*global ga*/

import MetabaseSettings from "metabase/lib/settings";


// Simple module for in-app analytics.  Currently sends data to GA but could be extended to anything else.
const MetabaseAnalytics = {
    // track a pageview (a.k.a. route change)
    trackPageView: function(url) {
        if (url) {
            // scrub query builder urls to remove serialized json queries from path
            url = (url.lastIndexOf('/q/', 0) === 0) ? '/q/' : url;

            const { tag } = MetabaseSettings.get('version');

            ga('set', 'dimension1', tag);
            ga('set', 'page', url);
            ga('send', 'pageview', url);
        }
    },

    // track an event
    trackEvent: function(category, action, label, value) {
        const { tag } = MetabaseSettings.get('version');

        // category & action are required, rest are optional
        if (category && action) {
            ga('set', 'dimension1', tag);
            ga('send', 'event', category, action, label, value);
        }
    }
}

export default MetabaseAnalytics;


export function registerAnalyticsClickListener() {
    document.body.addEventListener("click", function(e) {
        var node = e.target;

        // check the target and all parent elements
        while (node) {
            if (node.dataset && node.dataset.metabaseEvent) {
                // we expect our event to be a semicolon delimited string
                const parts = node.dataset.metabaseEvent.split(";").map(p => p.trim());
                MetabaseAnalytics.trackEvent(...parts);
            }
            node = node.parentNode;
        }
    }, true);
}
{'fraction_non_alphanumeric': 0.12488769092542677, 'fraction_numerical': 0.002395926924228811, 'mean_word_length': 2.1332082551594747, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '4201487', 'n_tokens_mistral': 915, 'n_tokens_neox': 884, 'n_words': 281}