Created
October 14, 2014 17:39
-
-
Save prettymuchbryce/02ad88e78f2af9e43374 to your computer and use it in GitHub Desktop.
Add utm params to link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var qs = require('qs') | |
var url = require('url') | |
var add_utm_params_to_link = function(link, utm_source, utm_medium, utm_content, utm_campaign) { | |
var parsed = url.parse(link) | |
var query = qs.parse(parsed.query) | |
query.utm_source = utm_source | |
query.utm_medium = utm_medium | |
query.utm_content = utm_content | |
query.utm_campaign = utm_campaign | |
parsed.search = qs.stringify(query) | |
return url.format(parsed) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment