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 1289.
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}); 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 = document.title + ' (Virtual)'; _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.
nebula.crm = function(action, data, sendNow){ //Write your own code here, leave it blank, or return false. }