How to get the referrer url within a hook

Hi Team,

I’m trying to add a metadata to a user based on the location from where they have arrived to register.
I’m seeing potential in using Hooks. I’m unable to extract the referrer url of the website however. Could anyone help with this please.

Basically I want to get the entire url and then slice it to get the a) domain and b) path

Assuming the user has come to the registration page from
www.mydomain.com/campaign/project1

I would like to extract them and add into metadata as

source_domain: www.mydomain.com
source_path: campaign/project1

// code
module.exports = function (user, context, cb) {
var response = {};
response.user = user;
context_webtask = context.webtask;
source_domain = context.webtask.headers.referer;
source_origin = context.webtask.headers.origin;
source_referer = JSON.stringify(context);
source_ip = context.request.ip;

// Add user or app metadata to the newly created user
response.user.user_metadata = { 
  source_domain: source_domain,
  source_origin:source_origin,
  source_referer: source_referer,
  source_ip: source_ip
};

cb(null, response);

};

The context json doesn’t contain the referrer and/or domain and path unfortunately. What is the best way to achieve this?

Hey there!

As this topic is related to Rules - Hooks - Actions and Rules & Hooks are being deprecated soon I’m excited to let you know about our next Ask me Anything session in the Forum on Thursday, January 18 with the Rules, Hooks and Actions team on Rules & Hooks and why Actions matter! Submit your questions in the thread above and our esteemed product experts will provide written answers on January 18. Find out more about Rules & Hooks and why Actions matter! Can’t wait to see you there!

Learn more here!