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?