<commit_before>import { createAction } from 'redux-act'

import analytics from 'src/analytics'
import internalAnalytics from 'src/analytics/internal'

export const setTrackingFlag = createAction(
    'privacy/setTrackingFlag',
    value => {
        // Value will be string from UI events, else bool from storage syncing
        if (typeof value === 'string') {
            return value === 'y'
        }

        return value
    },
)

export const toggleTrackingOptOut = value => async dispatch => {
    const newState = value === 'y' || value === true ? 'opt-in' : 'opt-out'

    const trackEvent = () =>
        analytics.trackEvent({
            category: 'Privacy',
            action: 'Change tracking pref',
            name: newState,
        })

    internalAnalytics.processEvent({
        type:
            'changeTrackingPref' + (newState === 'opt-in' ? 'OptIn' : 'OptOut'),
        force: true,
    })

    // Do event track after state change, as the event may be a noop if opt-out state is already set
    if (newState === 'opt-in') {
        dispatch(setTrackingFlag(value))
        await trackEvent()
    } else {
        await trackEvent()
        dispatch(setTrackingFlag(value))
    }
}<commit_msg>Add promise for trackEvent for both piwik and internalAnalytics<commit_after>import { createAction } from 'redux-act'

import analytics from 'src/analytics'
import internalAnalytics from 'src/analytics/internal'

export const setTrackingFlag = createAction(
    'privacy/setTrackingFlag',
    value => {
        // Value will be string from UI events, else bool from storage syncing
        if (typeof value === 'string') {
            return value === 'y'
        }

        return value
    },
)

export const toggleTrackingOptOut = value => async dispatch => {
    const isOptIn = value === 'y' || value === true

    const trackEvent = () => {
        const trackEvent = analytics.trackEvent({
            category: 'Privacy',
            action: 'Change tracking pref',
            name: isOptIn ? 'opt-in' : 'opt-out',
        })

        const processEvent = internalAnalytics.processEvent({
            type: isOptIn
                ? 'changeTrackingPrefOptIn'
                : 'changeTrackingPrefOptOut',
            force: true,
        })

        return Promise.all([trackEvent, processEvent])
    }

    // Do event track after state change, as the event may be a noop if opt-out state is already set
    if (isOptIn) {
        dispatch(setTrackingFlag(value))
        await trackEvent()
    } else {
        await trackEvent()
        dispatch(setTrackingFlag(value))
    }
}
{'fraction_non_alphanumeric': 0.1077041011881947, 'fraction_numerical': 0.0, 'mean_word_length': 2.3206106870229006, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '4416014', 'n_tokens_mistral': 721, 'n_tokens_neox': 715, 'n_words': 216}