Giter Club home page Giter Club logo

meteor-referrals's Introduction

Referrals

Adds a referral system to a Meteor app.

Documentation

This package works with Iron Router.

When a new visitor visits the site at example.com/some-path?r=SOME_REFERRER_CODE and then signs up, the SOME_REFERRER_CODE will be stored in the field referrerCode in Meteor.users.

Referrers are stored in the Referrers collection which contains the following fields:

  • code (unique)
  • name (optional)
  • url (optional)

This package also adds a referrerCode field to Meteor.users.

To make this work, add the following code to Accounts.onCreateUser on the server (or add the relevant code if you've already defined an Accounts.onCreateUser:

Accounts.onCreateUser(function (options, user) {
  // We still want the default hook's 'profile' behavior.
  if (options.profile)
    user.profile = options.profile;

  user.referrerCode = options.referrerCode;
  user.referrerClickId = options.referrerClickId;
  user.referrerSubId = options.referrerSubId;
  user.utmSource = options.utmSource;
  user.utmMedium = options.utmMedium;
  user.utmCampaign = options.utmCampaign;
  user.utmTerm = options.utmTerm;
  user.utmContent = options.utmContent;

  // if you'd like to track social login
  if (user.services.facebook || user.services.google) {
    user.askReferrer = true;
  }

  return user;
});

Add the following code somewhere on the client if you want to track social logins: (would love to find a better social to this)

Tracker.autorun(() => {
  const user = Meteor.user();

  if (!user || !user.askReferrer)
    return;

  const referrerCode = Referrer._referrerCode;
  const referrerClickId = Referrer.clickId;
  const referrerSubId = Referrer.subId;
  const utmSource = Referrer.utmSource;
  const utmMedium = Referrer.utmMedium;
  const utmCampaign = Referrer.utmCampaign;
  const utmTerm = Referrer.utmTerm;
  const utmContent = Referrer.utmContent;

  Meteor.call('setReferrer', {
    referrerCode,
    referrerClickId,
    referrerSubId,
    utmSource,
    utmMedium,
    utmCampaign,
    utmTerm,
    utmContent,
  });
});

And you need the following in your AccountsTemplates.configuration:

AccountsTemplates.configure({
  //...
  preSignUpHook: function (password, options) {
    Referrer.referralsPreSignUpHook(password, options);
  },
  //...
});

This package provides routes, publications, and templates for admin stuff. Admin is done using the alanning:roles package.

You can change the query field from r to something else by changing Referrer._referrerQuery. In the future we'll hopefully have a cleaner way of doing that.

The default for the currency symbol is £. You can change this to dollars by setting Referrer.currency = '$' for example.

Changelog

  • Commission (%) / CPA added.
  • Click tracking added.
  • Added UTM tracking.
  • Added postback option.

meteor-referrals's People

Contributors

elie222 avatar

Stargazers

Cos avatar Steve avatar  avatar

Watchers

James Cloos avatar  avatar U avatar  avatar

Forkers

cosmin-novac

meteor-referrals's Issues

Use with API login

This seems to only work for accounts-password, is there anyway to make it work with API logins such as accounts-google? I believe the issue is that it uses a preSignUpHook for the query parameters but since this requires a password I don't believe it will work for API logins. Is there anyway around this, maybe I'm just making a silly mistake, but I've been stuck on this for quite a while as it would fit perfectly with a project I'm working on.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.