Skip to Content
Menu

crm()

Sends visitor data to the CRM (default: Hubspot)

JavaScript February 7, 2021

Usage

JavaScript
nebula.crm(action, data, callback)

Parameters

action
(Required) (String) What will be done with the data
Default: None

data
(Required) (Object) The data to store
Default: None

sendNow
(Optional) (Boolean) Send a virtual pageview to work with Hubspot Free CRM
Default: true

Parameter Notes

Action can be “identify” or “event”.

Data is stored as an object of {property: value}.

Request or provide clarification »

Examples

Send multiple columns of data in the same function

JavaScript
nebula.crm('identify', {
    favorite_color: 'green',
    favorite_nfl_team: 'Philadelphia Eagles'
});

Send multiple columns of data in the same function call (using core Hubspot API, for reference). This particular example would be embedded in a PHP script.

JavaScript
_hsq.push(["identify", {
    ipaddress: '<?php echo $_SERVER['REMOTE_ADDR']; ?>',
    user_agent: '<?php echo $_SERVER['HTTP_USER_AGENT']; ?>',
    session_id: '<?php echo nebula()->nebula_session_id(); ?>',
}]);

Additional Notes

This function requires the Hubspot Portal ID in Nebula Options.

Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /assets/js/modules/analytics.js on line 1362.

    No Hooks

    This function does not have any filters or actions available. Request one?
    JavaScript
    nebula.crm = async function(action, data, sendNow = true){
        if ( nebula.isDoNotTrack() ){
            return false;
        }
    
        if ( typeof _hsq === 'undefined' ){
            return false;
        }
    
        if ( !action || !data || typeof data == 'function' ){
            nebula.help('Action and Data Object are both required in nebula.crm().', '/functions/crm/');
            return false; //Action and Data are both required.
        }
    
        if ( action === 'identify' ){
            _hsq.push(['identify', data]);
    
            jQuery.each(data, function(key, value){
                nebula.user[key] = value;
            });
    
            if ( sendNow ){
                //Send a virtual pageview because event data doesn't work with free Hubspot accounts (and the identification needs a transport method)
                _hsq.push(['setPath', window.location.href.replace(nebula.site.directory.root, '') + '#virtual-pageview/identify']);
                _hsq.push(['trackPageView']);
            }
            //_hsq.push(["trackEvent", data]); //If using an Enterprise Marketing subscription, use this method instead of the trackPageView above
    
            //Check if email was identified or just supporting data
            if ( 'email' in data ){
                if ( !nebula.user.known && nebula.regex.email.test(data.email) ){
                    nebula.dom.document.trigger('nebula_crm_identification', {email: nebula.regex.email.test(data.email), data: data});
                    ga('send', 'event', 'CRM', 'Contact Identified', "A contact's email address in the CRM has been identified.");
                    nebula.user.known = true;
                }
            } else {
                nebula.dom.document.trigger('nebula_crm_details', {data: data});
                ga('send', 'event', 'CRM', 'Supporting Information', 'Information associated with this user has been identified.');
            }
        }
    
        if ( action === 'event' ){
            //Hubspot events are only available with an Enterprise Marketing subscription
            //Refer to this documentation for event names and IDs: https://developers.hubspot.com/docs/methods/tracking_code_api/tracking_code_overview#idsandnames
            _hsq.push(['trackEvent', data]);
    
            _hsq.push(['setPath', window.location.href.replace(nebula.site.directory.root, '') + '#virtual-pageview/' + data]);
            let oldTitle = document.title;
            document.title += ' (Virtual)'; //Append to the title
            _hsq.push(['trackPageView']);
            document.title = oldTitle;
        }
    
        nebula.dom.document.trigger('crm_data', data);
    };
    

    Override

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

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