Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

this assumes you have node and npm installed

  1. put branch-sdk.js and sendgrid-demo.js in the same directory
  2. run node sendgrid-demo.js in that directory to examine the sample output

Note: for actual usage, be sure to use your app's branch_base_url, rather than as provided in the example.

module.exports = function(original_url, branch_base_url) {
if (!original_url) { return new Error('Missing original_url'); }
if (typeof original_url != 'string') { return new Error('Invalid original_url'); }
if (!branch_base_url) { return new Error('Missing branch_base_url, should be similar to'); }
if (typeof branch_base_url != 'string') { return new Error('Invalid branch_base_url'); }
return branch_base_url + '&%24original_url=' + encodeURIComponent(original_url);
// Javascript SendGrid Demo -- `node sendgrid-demo.js`
var branchSDK = require('./branch-sdk'),
BRANCH_BASE_URL = ''; // replace this with the BRANCH_BASE_URL provided by Branch
var body = '<html><body><a id="some-id" class="some-class" href="">Destined to be a clickable deep link</a><a id="some-id" class="some-class" href="">mix it up</a></body></html>';
body = body.replace(/(<a\s(:?.|\s)*?href=")(.+?)(")/gi, function(v1, v2, v3, v4, v5) {
return v2 + branchSDK(v4, BRANCH_BASE_URL) + v5;
console.log('new body ready to be sent via email:\n', body);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.