Usage
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}
.
Examples
Send multiple columns of data in the same function
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.
_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.
Source File
Located in /assets/js/modules/analytics.js on line 1557.
No Hooks
This function does not have any filters or actions available. Request one?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}); gtag('event', 'Contact Identified', { event_category: 'CRM', event_label: "A contact's email address in the CRM has been identified.", non_interaction: true }); nebula.user.known = true; } } else { nebula.dom.document.trigger('nebula_crm_details', {data: data}); gtag('event', 'Supporting Information', { event_category: 'CRM', event_label: 'Information associated with this user has been identified.', non_interaction: true }); } } 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. Remember: Some functionality is conditionally loaded via dynamic imports, so if your function is not overriding properly, try listening for a DOM event (described below).
For non-module import functions:
nebula.crm = function(action, data, sendNow){ //Write your own code here, leave it blank, or return false. }
For dynamically imported module function overrides:
jQuery(window).on('load', function(){ nebula.crm = function(action, data, sendNow){ //Write your own code here, leave it blank, or return false. } });
Custom Nebula DOM events do also exist, so you could also try the following if the Window Load listener does not work:
jQuery(document).on('nebula_module_loaded', function(module){ //Note that the module variable is also available to know which module specifically was imported if ( typeof nebula.crm === 'function' ){ nebula.crm = function(action, data, sendNow){ //Write your own code here, leave it blank, or return false. } } });