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 22, 2017

Usage

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

Source File

Located in /assets/js/nebula.js on line 2283.

Note: This function contains 1 to-do comment.

JavaScript
nebula.pageSuggestion = function(){
    if ( nebula.dom.body.hasClass('search-no-results') || nebula.dom.body.hasClass('error404') ){
        if ( nebula.has(nebula, 'site.options') && nebula.site.options.nebula_cse_id !== '' && nebula.site.options.nebula_google_browser_api_key !== '' ){ //@todo "Nebula" 0: Replace with optional chaining
            if ( nebula.get().length ){
                var queryStrings = nebula.get();
            } else {
                var queryStrings = [''];
            }
            var path = window.location.pathname;
            var phrase = decodeURIComponent(path.replace(/\/+/g, ' ')).trim() + ' ' + decodeURIComponent(queryStrings[0].replace(/\+/g, ' ')).trim();
            nebula.tryGCSESearch(phrase);
        }

        nebula.dom.document.on('mousedown', 'a.gcse-suggestion, a.internal-suggestion', function(e){
            var thisEvent = {
                event: e,
                category: 'Page Suggestion',
                action: ( jQuery(this).hasClass('internal-suggestion') )? 'Internal' : 'GCSE',
                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.nv('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.
}