Skip to Content

pageSuggestion()

Offer page suggestions from an external related search using the Google Custom Search Engine on 404 pages and no search result pages.

JavaScript February 7, 2021

Usage

This function runs automatically, so it is not called manually. Is this incorrect?

Source File

Located in /assets/js/modules/search.js on line 368.

No Hooks

This function does not have any filters or actions available. Request one?
JavaScript
nebula.pageSuggestion = async function(){
    if ( nebula.dom.body.hasClass('search-no-results') || nebula.dom.body.hasClass('error404') ){
        if ( nebula.site?.options?.nebula_cse_id !== '' && nebula.site?.options?.nebula_google_browser_api_key !== '' ){

            let queryStrings;
            if ( nebula.get().length ){
                queryStrings = nebula.get();
            } else {
                queryStrings = [''];
            }

            let path = window.location.pathname;
            let phrase = decodeURIComponent(path.replaceAll(/\/+/g, ' ')).trim() + ' ' + decodeURIComponent(queryStrings[0].replaceAll(/\+/g, ' ')).trim();
            nebula.tryGCSESearch(phrase);
        }

        nebula.dom.document.on('mousedown', 'a.gcse-suggestion, a.internal-suggestion', function(e){
            let thisEvent = {
                event: e,
                category: 'Page Suggestion',
                action: ( jQuery(this).hasClass('internal-suggestion') )? 'Internal' : 'GCSE', //GA4 name: "select_content"
                intent: ( e.which >= 2 )? 'Intent' : 'Explicit',
                suggestion: jQuery(this).text(),
            };

            ga('set', nebula.analytics.dimensions.eventIntent, thisEvent.intent);
            nebula.dom.document.trigger('nebula_event', thisEvent);
            ga('send', 'event', thisEvent.category, thisEvent.action, thisEvent.suggestion);
            nebula.crm('event', 'Page Suggestion Click');
        });
    }
};

Override

To override or disable this JavaScript function, simply redeclare it with the exact same function name.

JavaScript
nebula.pageSuggestion = function(){
    //Write your own code here, leave it blank, or return false.
}