⚙ Operations Hub

HubSpot Employee
HubSpot Employee

Q&A Follow-up | Custom Automation Workshop on creating a referral program

Hi everyone,


Thank you for joining todays session. It's greatly appreciated and it was a pleasure to speak with you all today. I hope that you found the workshop useful and if anything you've left with some interesting ideas that might help you to build on what we covered today. 


The slides can be found here.


We got so many amazing questions and I'd love to take a moment to address them all. If you have any other questions in relation to what we covered in the workshop please do not hesitate to leave a comment.


Also worth noting that we'll be running our fourth (and final) session next week. During the workshop we will be covering how to connect and query an external database.Sign up here if you are interested!


Q. I have a unique use case that I’m trying to solve. We want to trigger a contact into a workflow based off of preferred language, locale and viewing a page (not filling out a form). Could we use behavioral event?

A. Providing the preferred language and locale are captured in contact properties this could be achieved by creating a workflow and enrolling using criteria similar to the below:


Screenshot 2022-02-17 at 21.41.06.png


Custom Behavioural Events wouldn't be needed in this instance but worth noting that they're incredibly powerful and would allow you to track more advance user activity on your site, or within your web/mobile application.


Q. I really like all of the use cases we’re showing here with the automation masterclass sessions but we don’t have budget to upgrade from Operations Hub starter to enterprise. Is there a way we could leverage other tools (like Zapier) where we could use the same logic and code? Thanks

A. There wouldn't be a need to go from starter to enterprise as custom coded workflow actions are a feature of Operations Hub Professional. At a minimum you would need Marketing Professional and Operations Hub Professional to achieve what we covered in the workshop. More information on pricing can be found here.


Q. If we do not have the HS subscription that gives us this developer access, are the functions & automations presented in your webinars available to us through paid consulting?

A. Providing you are on Marketing Hub and Operations Hub Professional you will be able to implement this type of solution in your account. However, I understand that there is a technical element to it that would require some level of proficiency with either Javascript or Python. We offer technical consulting that could help you here or alternatively you could work with one of our partners who could help you get this setup along with much much more!


Q. In the event a customer signs up for referral program who has previously opted out for all email, how would you solve for that?

A. HubSpot provides functionality to solve for this, more information here. In short, if a contact interacts with a form that has previously opted out of all email they'll be shown a message and prompted to resubscribe.


Q. if generating a random number, do you not need to validate that the number has not already been generated to avoid duplicates?

A. You could certainly add another level of validation if you'd like. One option here might be to use our CRM Search API upon generating the code to see if there is a matching contact already. In which case you would re-generate the number. Just be mindful that each custom coded worklfow action has a maximum runtime of 20 seconds. 


Q. Would be possible to use the Hubspot contact ID instead of the Referer ID?

A. Certaintly, this is possible. If you did this you could replace the custom coded worklfow action in workflow 1 with the "copy property value" action. See below:


Screenshot 2022-02-17 at 21.55.02.png

Q. We have a two tiered affiliate program. Would what you are showing us still apply to this type of structure?

A. I'd be keen to understand a little bit more about this use case but certainly what we covered in the workshop today could be refactored for a variety of purposes. 


Q. how many npm packages are supported by the custom code environment.?

A.  If you're using Node.js, the following libraries are available for use within the code action. These libraries can be loaded using the normal require() function at the top of your code.


  • @hubspot/api-client ^3.4.1
  • async ^3.2.0
  • aws-sdk ^2.858.0
  • axios ^0.20.0
  • lodash ^4.17.20
  • mongoose ^5.11.19
  • mysql ^2.18.1
  • redis" ^3.0.2
  • request" ^2.88.2
  • bluebird 3.7.2
  • random-number-csprng 1.0.2
  • googleapis 67.1.1

More information can be found here.


Q. Is there a way to automate segmenting/tracking a referrer's number of referrals sent, sign-up's & made purchases from refferals?

A. One option here could be that you copy the referrer ID to the deal when it's created. This could happen automatically if you setup a workflow. You could then create deal based reports by refferer ID. 


Q. what if an identical contact uses two referral forms (two IDs) - will it overwrite the previous or create a new contact for each re-entry

A. If they're using the same device the simplest option would be to prevent re-enrollment into the worklfow. This is the default. In otherwords the workflow to generate the unique code would not run a second time. There isn't a perfect solution to avoid this if individuals are doing this from multiple devices. It's more of a question of minimising the potential for this type of thing.


Q. Would it be possible to do an import and update Number of referrals property for existing referrers who referred before using this automation, would that impact any of the custom code?

A. Yes, certainly this is possible. You'd just follow the instructions to perform a standard import as per this article


Q. Can you change someone's Referrer ID after creation?

A. Yes, you could manually change this if you wish. Just make sure to setup a workflow to notify the contact of this change.


Q. Would there be a way to do this with Operations hub starter? We dont have the professional is it worth to pay for operations hub professional just for refferal program?

A. There are ways to achieve this using iPaaS solutions like Zapier. However you will lack the flexibility of what we covered in today session. If you're interested in learning a little bit more about how you could use Zapier for this feel free to check out this video. It's somewhat outdated today but I recorded this prior to the launch of Operations Hub in April of last year.


Q. what’s npm?

A. NPM is an acronym for "Node Package Manager". This is a tool that allows you to import various packages (or libraries) that provide additional functionality on top of the native functionality provided with NodeJS. Currently we support the packages listed here.


Q. I noticed that the Hubspot client is fairly outdated. Is there any plan to update the client for custom code actions?

A. At present custom coded workflow actions support @hubspot/api-client ^3.4.1. In the future, we'd like to get to a stage whereby individuals could specify a version they'd like to use.


Q. Following up on the attribution question / is there a way to only “count” deals /referred contacts who were referred before another conversion? Perhaps adding a referral time stamp and making sure that it’s the same date as first conversion date?

A. Certainly worth exploring in more detail. You could use a time between calculated property to assist with this. More information here


Q. Is there a way to host this Referral Workflow custom code in the Private App using the Serverless Function?

A. There certainly would be a way to build this out using serverless functions. Just be mindful that this requires a CMS Hub Enterprise license. 



I hope the above is helpful and as I said before if you've any other questions please do not hesitate to leave a comment below. Thank you again for joining and hope to see you at our next session!

Jack Coldrick
Solutions Engineer @ HubSpot
Add me on LinkedIn
3 Replies 3

Q&A Follow-up | Custom Automation Workshop on creating a referral program

Hi @jackcoldrick,


I wonder if you have the Python version of the code for the referral program. If yes, could you please share it with me?


And what I want to do is created a company-based referral program rather than a contact-based referral program. Do you have any idea about it?




HubSpot Employee
HubSpot Employee

Q&A Follow-up | Custom Automation Workshop on creating a referral program

Hi @jackcoldrick ,


I built out your referral program but I'm finding that the 'number of referrals' property isn't functioning. I signed up to the "referral program" with a personal email address and signed up to that referral link using another email address but it's not registerting it in the CRM yet.


Any thought on why this is?




Screenshot 2022-02-21 at 13.15.16.png

HubSpot Employee
HubSpot Employee

Q&A Follow-up | Custom Automation Workshop on creating a referral program

Hey @RachelKenny thanks for the question, the reason this is happening is because the "Recent Referral Date" property had an internal name of "referral_date" and the code was trying to update a property called "recent_referral_date". As a result the entire update failed. I've adjusted this for you now and it should all be working as expected 🙂 

Jack Coldrick
Solutions Engineer @ HubSpot
Add me on LinkedIn