return ( dispatch, getState ) => { const enabling = ! isEnabled( getState() ); const doing = enabling ? 'enabling' : 'disabling'; debug( doing ); dispatch( { type: PUSH_NOTIFICATIONS_TOGGLE_ENABLED } ); if ( enabling ) { dispatch( fetchAndLoadServiceWorker() ); dispatch( recordTracksEvent( 'calypso_web_push_notifications_enabled' ) ); } else { dispatch( deactivateSubscription() ); dispatch( recordTracksEvent( 'calypso_web_push_notifications_disabled' ) ); } };
export function uploadGravatar( file, email ) { return withAnalytics( recordTracksEvent( 'calypso_edit_gravatar_upload_start' ), { type: GRAVATAR_UPLOAD_REQUEST, file, email, } ); }
.then( data => { const newSlug = get( data, 'new_slug' ); if ( newSlug ) { dispatch( recordTracksEvent( 'calypso_siteaddresschange_success', eventProperties ) ); const newAddress = newSlug + '.wordpress.com'; dispatch( requestSite( siteId ) ).then( () => { page( domainManagementEdit( newAddress, newAddress ) ); dispatch( successNotice( translate( 'Your new site address is ready to go!' ), { id: 'siteAddressChangeSuccessful', duration: 5000, showDismiss: true, isPersistent: true, } ) ); } ); } dispatch( { type: SITE_ADDRESS_CHANGE_REQUEST_SUCCESS, newSlug, siteId, } ); } )
return ( dispatch, getState ) => { const themeAction = { type: THEMES_RECEIVE, siteId: site.ID, isJetpack: !! site.jetpack, wasJetpack: isJetpack( getState() ), themes: data.themes, found: data.found, queryParams: queryParams }; const trackShowcaseSearch = recordTracksEvent( 'calypso_themeshowcase_search', { search_term: queryParams.search || null, tier: queryParams.tier, response_time_in_ms: responseTime, result_count: data.found, results_first_page: data.themes.map( property( 'id' ) ) } ); const action = isFirstPageOfSearch( queryParams ) ? withAnalytics( trackShowcaseSearch, themeAction ) : themeAction; dispatch( action ); };
return ( dispatch, getState ) => { const timeBucket = bucketedTimeSpentOnCurrentView( getState() ); const config = getConfigForCurrentView( getState() ); if ( ! config || ! config.name ) { return false; } const hideAction = { type: FIRST_VIEW_HIDE, view: config.name, }; const tracksEvent = recordTracksEvent( `calypso_first_view_dismissed`, { view: config.name, showAgain: enabled, timeSpent: timeBucket, } ); dispatch( bumpStat( 'calypso_first_view_dismissed', enabled ? 'show_again' : 'dont_show' ) ); dispatch( bumpStat( 'calypso_first_view_duration', timeBucket ) ); dispatch( tracksEvent ); dispatch( hideAction ); dispatch( persistToPreferences( { getState, view: config.name, disabled: ! enabled } ) ); };
return dispatch => { dispatch( { type: PUSH_NOTIFICATIONS_BLOCK } ); dispatch( deactivateSubscription() ); dispatch( recordTracksEvent( 'calypso_web_push_notifications_blocked' ) ); };
return request().then( ( { themes: rawThemes, info: { results } = {}, found = results } ) => { let themes; if ( siteId === 'wporg' ) { themes = map( rawThemes, normalizeWporgTheme ); } else if ( siteId === 'wpcom' ) { themes = map( rawThemes, normalizeWpcomTheme ); } else { // Jetpack Site themes = map( rawThemes, normalizeJetpackTheme ); } if ( ( query.search || query.filter ) && query.page === 1 ) { const responseTime = ( new Date().getTime() ) - startTime; const search_taxonomies = prependThemeFilterKeys( getState(), query.filter ); const search_term = search_taxonomies + ( query.search || '' ); const trackShowcaseSearch = recordTracksEvent( 'calypso_themeshowcase_search', { search_term: search_term || null, search_taxonomies, tier: query.tier, response_time_in_ms: responseTime, result_count: found, results_first_page: themes.map( property( 'id' ) ).join() } ); dispatch( trackShowcaseSearch ); } dispatch( receiveThemes( themes, siteId, query, found ) ); } ).catch( ( error ) => {
export const recordUseYourDomainButtonClick = ( section, source ) => composeAnalytics( recordGoogleEvent( 'Domain Search', 'Clicked "Use a Domain I own" Button' ), recordTracksEvent( 'calypso_domain_search_results_use_my_domain_button_click', { section, source, } ) );
export const receiveRestoreError = ( { siteId, timestamp }, error ) => error.hasOwnProperty( 'schemaErrors' ) ? withAnalytics( recordTracksEvent( 'calypso_rewind_to_missing_restore_id', { site_id: siteId, timestamp } ), errorNotice( translate( "Oops, something went wrong. We've been notified and are working on resolving this issue." ) ) ) : withAnalytics( recordTracksEvent( 'calypso_rewind_to_unknown_error', error ), errorNotice( translate( 'Oops, something went wrong. Please try again soon or contact support for help.' ) ) );
export function recordFiltersSubmit( filters, section ) { return composeAnalytics( recordGoogleEvent( 'Domain Search', 'Filters Submit' ), recordTracksEvent( 'calypso_domain_search_filters_submit', { section, ...processFiltersForAnalytics( filters ), } ) ); }
export const onError = () => { return [ errorNotice( "We couldn't cancel your session, please try again later." ), withAnalytics( recordTracksEvent( 'calypso_concierge_appointment_cancellation_error' ), updateConciergeBookingStatus( CONCIERGE_STATUS_CANCELLING_ERROR ) ), ]; };
export function recordFiltersReset( filters, keysToReset, section ) { return composeAnalytics( recordGoogleEvent( 'Domain Search', 'Filters Reset' ), recordTracksEvent( 'calypso_domain_search_filters_reset', { keys_to_reset: keysToReset.join( ',' ), section, ...processFiltersForAnalytics( filters ), } ) ); }
export function recordShowMoreResults( searchQuery, pageNumber, section ) { return composeAnalytics( recordGoogleEvent( 'Domain Search', 'Show More Results' ), recordTracksEvent( 'calypso_domain_search_show_more_results', { search_query: searchQuery, page_number: pageNumber, section, } ) ); }
export const receiveGravatarImageFailed = ( { errorMessage, statName } ) => withAnalytics( composeAnalytics( recordTracksEvent( 'calypso_edit_gravatar_file_receive_failure' ), bumpStat( 'calypso_gravatar_update_error', statName ) ), { type: GRAVATAR_RECEIVE_IMAGE_FAILURE, errorMessage, } );
.then( ( { status, message, uploaded_theme_slug } ) => { dispatch( transferStatus( siteId, transferId, status, message, uploaded_theme_slug ) ); if ( status === 'complete' ) { // finished, stop polling const context = !! uploaded_theme_slug ? 'themes' : 'plugins'; dispatch( recordTracksEvent( 'calypso_automated_transfer_complete', { transfer_id: transferId, context } ) ); return resolve(); } // poll again return delay( pollStatus, interval, resolve, reject ); } )
return dispatch => { const themeInitiateFailureAction = { type: THEME_TRANSFER_INITIATE_FAILURE, siteId, error, }; dispatch( withAnalytics( recordTracksEvent( 'calypso_automated_transfer_initiate_failure', { plugin, context } ), themeInitiateFailureAction ) ); };
export const recordRemoveDomainButtonClick = ( domainName ) => composeAnalytics( recordGoogleEvent( 'Domain Search', 'Clicked "Remove" Button on a Domain Registration', 'Domain Name', domainName ), recordTracksEvent( 'calypso_domain_remove_button_click', { domain_name: domainName, } ), );
export function announceFailure( { dispatch } ) { dispatch( withAnalytics( composeAnalytics( recordTracksEvent( 'calypso_edit_gravatar_upload_failure' ), bumpStat( 'calypso_gravatar_update_error', 'unsuccessful_http_response' ) ), { type: GRAVATAR_UPLOAD_REQUEST_FAILURE } ) ); }
export const onSuccess = ( { type } ) => { const trackEvent = CONCIERGE_APPOINTMENT_RESCHEDULE === type ? 'calypso_concierge_appointment_rescheduling_successful' : 'calypso_concierge_appointment_booking_successful'; return withAnalytics( recordTracksEvent( trackEvent ), updateConciergeBookingStatus( CONCIERGE_STATUS_BOOKED ) ); };
fileReader.addEventListener( 'load', () => { dispatch( { type: GRAVATAR_UPLOAD_RECEIVE, src: fileReader.result, } ); dispatch( withAnalytics( recordTracksEvent( 'calypso_edit_gravatar_upload_success' ), { type: GRAVATAR_UPLOAD_REQUEST_SUCCESS, } ) ); } );
export const recordAddDomainButtonClickInMapDomain = ( domainName, section ) => composeAnalytics( recordGoogleEvent( 'Domain Search', 'Clicked "Add" Button on a Domain Registration in Map Domain Step', 'Domain Name', domainName ), recordTracksEvent( 'calypso_map_domain_step_add_domain_click', { domain_name: domainName, section } ), );
export const recordAddDomainButtonClick = ( domainName, section ) => composeAnalytics( recordGoogleEvent( 'Domain Search', 'Clicked "Add" Button on a Domain Registration', 'Domain Name', domainName ), recordTracksEvent( 'calypso_domain_search_add_button_click', { domain_name: domainName, section, } ), );
export const recordGoButtonClickInMapDomain = ( searchBoxValue, section ) => composeAnalytics( recordGoogleEvent( 'Domain Search', 'Clicked "Go" Button in Map Domain Step', 'Search Box Value', searchBoxValue ), recordTracksEvent( 'calypso_map_domain_step_go_click', { search_box_value: searchBoxValue, section } ), );
const errorHandler = error => { dispatch( recordTracksEvent( 'calypso_siteaddresschange_error', { ...eventProperties, error_code: error.code, } ) ); dispatchErrorNotice( dispatch, error ); dispatch( { type: SITE_ADDRESS_CHANGE_REQUEST_FAILURE, error: error.message, siteId, } ); };
export function recordTldFilterSelected( tld, position, isSelecting ) { return composeAnalytics( recordGoogleEvent( 'Domain Search', isSelecting ? 'Clicked TLD Filter Button To Select' : 'Clicked TLD Filter Button To Deselect' ), recordTracksEvent( isSelecting ? 'calypso_domain_search_results_tld_filter_select' : 'calypso_domain_search_results_tld_filter_deselect', { tld, position } ) ); }
export const onError = ( { type }, error ) => { const trackEvent = CONCIERGE_APPOINTMENT_RESCHEDULE === type ? 'calypso_concierge_appointment_rescheduling_error' : 'calypso_concierge_appointment_booking_error'; return [ withAnalytics( recordTracksEvent( trackEvent ), updateConciergeBookingStatus( CONCIERGE_STATUS_BOOKING_ERROR ) ), errorNotice( errorMessage( error.code ) ), ]; };
export function nextGuidedTourStep( { tour = 'main', stepName } ) { const nextAction = { type: GUIDED_TOUR_UPDATE, stepName, }; const trackEvent = recordTracksEvent( 'calypso_guided_tours_next_step', { step: stepName, tour_version: guidedToursConfig.get( tour ).version, tour, } ); return withAnalytics( trackEvent, nextAction ); }
export function showGuidedTour( { shouldShow, shouldDelay = false, tour = 'main' } ) { const showAction = { type: GUIDED_TOUR_SHOW, shouldShow, shouldDelay, tour, }; const trackEvent = recordTracksEvent( 'calypso_guided_tours_show', { tour_version: guidedToursConfig.get( tour ).version, tour, } ); return shouldDelay ? showAction : withAnalytics( trackEvent, showAction ); }
return ( dispatch, getState ) => { const timeBucket = bucketedTimeSpentOnCurrentView( getState() ); const tracksEvent = recordTracksEvent( `calypso_first_view_dismissed`, { view, showAgain: enabled, timeSpent: timeBucket, } ); dispatch( bumpStat( 'calypso_first_view_dismissed', enabled ? 'show_again' : 'dont_show' ) ); dispatch( bumpStat( 'calypso_first_view_duration', timeBucket ) ); dispatch( tracksEvent ); dispatch( hideAction ); dispatch( persistToPreferences( { getState, view, disabled: ! enabled } ) ); };
export const recordSearchResultsReceive = ( searchQuery, searchResults, responseTimeInMs, resultCount, section ) => composeAnalytics( recordGoogleEvent( 'Domain Search', 'Receive Results', 'Response Time', responseTimeInMs ), recordTracksEvent( 'calypso_domain_search_results_suggestions_receive', { search_query: searchQuery, results: searchResults.join( ';' ), response_time_ms: responseTimeInMs, result_count: resultCount, section, } ) );