How to attach URL query parameters to a user during the sign up process. Possible?


I am trying to add a referral system to my project, so currently I am basing it off of this package. The issue I am running into is my project only uses accounts-google and not accounts-password. The way this package works is it adds the iron router query parameters for the referrerCode (/register?r=ReferralCodeHere)through a preSignUpHook. I believe this only works with accounts-password wont work when creating an account with an API such as accounts-google.

My idea around this is to use a Meteor.users.before.insert hook to grab the iron router query parameters and insert them into my referrerCode field in Meteor.users since I’m already using Meteor Collection Hooks for a couple of other things.

The issue is I havent been able to find a way to get the query parameters on the server, I was hoping to do something like this:

Meteor.users.before.insert(function(userId, doc) {
  doc.referrerCode = Referrer._referrerCode; // Link 1 

(Link 1)

But this will just come up as undefined.

If I’m at my register page and it has a query like this for example: Then I run Router.current().params.query.r on the client it returns 12345. Basically I just need to have that saved to the referralCode field in Meteor.users when a new user creates an account, if a referral code exists in the register URL.

I’m a bit lost with this one. I thought about setting it as a Session variable and then getting that in the before.insert hook, but that again only works on the client side. I’m thinking a meteor method might be best for this, but I’m not exactly sure how I would structure it.

Any help is greatly appreciated!


If anyone has any ideas of another way that I can make this work I’d definitely appreciate hearing them, nothing I’ve tried seems to work and been stuck on this for a couple weeks now.

I basically just need a system so that users are able to have a referral code which goes in the register url (, which they can then share and when new users sign up using their referral link it will be tracked. It seems like this package would work good for this but unfortunately that one and every other one I’ve seen only works for accounts-password and not any API logins such as accounts-google (which is what my login system uses).

As I said above, the main issue seems to be getting the referral ID from the URL. This is easy to get using Iron-Router query parameters but that is only available from the client, so to get this during signup and attached to the user account is where I’m quite lost. I was hoping to use a Meteor.users.before.insert hook but I still cant find a way to get the query parameters into the server…

Any ideas or anything at all is greatly appreciated, I feel like this should be much easier than it’s been :confused:


How about having a custom handler like this:

WebApp.connectHandlers.use("/url?var1=val1...", function(req, res, next) {

Then save these values somewhere that you reuse when the user logs in / creates account


Thanks for the reply!

As an update, I’m not too familiar with connectHandlers, but I’ve been reading up on it and trying a few things but haven’t been able to make anything work so far.

I’ll continue to fiddle around with connectHandlers, but if anyone else has any suggestions I’m also open to hearing them. This seems like it should be much easier than its been, 2 weeks of being stuck on this one little thing is pretty brutal, unfortunately it’s also an important step before I can continue to other areas of my project as well…


So I saw this a few days ago and it bothered me a bit that something that seems simple is causing issues… Not sure this is the best way to do it, but the duct-taper in me thinks it may work?

  1. Check the docs below (form field config) for a way to add a hidden field to your atForm.
  2. In an onRendered, pull the referral code from your route and put it into your hidden field.
  3. Use Accounts.onCreateUser to grab the value from the hidden field and attach it to the user doc

Form Field Configuration
Extending Meteor Users


Thinking some more …
when you use connectHandlers, use cookies as you don’t yet have a session. Then when you redirect to login / create user account, load up the cookies.


I’m having basically the same issue. It’s such a disappointment that this isn’t covered in the accounts-core/ui package…

I think the only way to do it is to roll your own signup form and use Accounts.createUser… otherwise there is no way to get a session variable to the server’s Accounts.onCreateuser

I tried to store it in ‘info’ in the preSignUpHook, then add the document in the postSignUpHook once the user is created and I have the userId… but the preSignUpHook seems to wipe the session variable to it’s original state… it comes back empty (I initialize it as empty in an Template.onCreated).

I’ve come across this same use case probably 15 times but it doesn’t seem like whoever oversees accounts-core is interested in adding it… even though it could be a simple hook, instead anyone needing this is forced to roll their own.


I agree I would love to see a way built into accounts-core to make this process easier, it’s been quite frustrating and caused quite a delay. Thankfully I have everything working now, but the process isn’t super clean.

I’d suggest checking out the referrals package which I was originally basing my system off of. The creator recently did an update making it possible to support social login. It’s a pretty hacky solution but after the amount of time I was stuck on this it’s the only way I was able to make things work.

Hopefully we’ll soon see an update to accounts-core to solve this issue. There are loads of use cases and I’m sure it would help a ton of people.


So I implemented a roughly similar system. Instead of a referral argument, my system is keying off document.referrer and I save that to the user’s profile.

Implementation took me about 20-25 minutes. I’m not using any hooks into the login system.

When someone loads up the website, I save the referrer to a client side variable when my header loads. After login, when the newly registered user loads the first authenticated page I will look at his user information. If there is no user.profile.referrer value (since this is not a hook but happens every load), I call a server function to write the previously saved referrer variable as the referrer and I’m done.

Seems to work for me so far. Obviously my method has potential issues with someone refreshing a page. I’ll see what % of my users have issues in time.


As the author of the super hacky package, I think I did try and make changes to accounts core at the time, but I think the issue was more on the meteor level of how accounts-facebook and other social login packages work. Meteor doesn’t give an option to pass in additional parameters when registering a user through social login.

One idea might be to create a wrapper method for loginwithfacebook and all the other social login methods. But I feel like that method could also end up being pretty hacky if you even managed to get that idea to work.

The best would seem to be to open an issue on the meteor github repo for loginwithsocial to receive an extra parameter of additional data to be added to the user document.