Website Logo. Upload to /source/logo.png ; disable in /source/_includes/logo.html

Chris Meier

Software Developer and Co-founder of FoodChain

Automating Beta Signup and Distribution

I previously talked about the importance of automating what you can at your startup. This frees up valuable time to work of what really matters and focus your attention. It can also help prevent mistakes resulting from human error. In this post, I will show you how to automate your beta signup and distribution process. The tutorial will use Node.js and Express.js. If you don’t already have those installed, I would recommend that you do that before going any further.

Crashlytics

It is highly beneficial to use a framework for beta testing. You can package it with your app and get detailed crash reports sent back to you. For this tutorial, we will be using Crashlytics. After you register for an account and build your app, be sure to get a distribution link. This allows your app to be downloaded directly.

Mailgun

There are a few different email API services out there. We chose Mailgun over Mandrill because they have free tier. You will need to register an account with them and set up a domain. This will allow the emails to be sent automatically to your testers.

Node

Now we get to the meaty part. This assumes that you already have a client side signup form that can make an AJAX call to the server. This is very easy to do and quickly learned if you don’t know how to do it.

First, we will setup an simple Express app with a “signup” endpoint. All signup requests will go to this endpoint via the AJAX call. The server will then take care of all of the logic needed for a tester to signup and get your app. We will fill the logic in section by section.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var express = require('express');
app = express();

var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));

var Mailgun = require("mailgun-js");

var mailgunKey = YOUR-MAILGUN-API-KEY;

//from your mailgun dashboard
var domainName = YOUR-DOMAIN.com;

//Email the message will be sent from
var sendingEmail = your@email.com;

//link to app download provided by crashlytics
var distroLink = YOUR-URL;

app.post('/signup', function(req, res){
    var mailgun = new Mailgun({apiKey: mailgunKey, domain: domainName});
    //get name and email

    //insert into database

    //construct message

    //send message

});

Filling It All In

Get Name and Email

First, we will need to get the name and email of the tester. This is very simple and can be accessed via the request’s body.

1
2
var testerName = req.body.name;
var testerEmail = req.body.email;

Insert into Database

I have skipped this part since I wanted to keep the focus on the automation aspect. You simply insert the user’s name and email into the whichever database you are using. I will leave this as an exercise for the reader.

Construct Message

Next, we need to construct the message we will be sending to the tester. The tester’s email and name (to make it more personal), and the distribution link will need to be included. Here, we use HTML for the email body. I found it a bit more expressive than plain-text. Plain-text is an option and you can visit the Mailgun documentation to learn more.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
var data = {
    //Specify email data
      from: sendingEmail,
    //The email to contact
      to: testerEmail,
    //Subject and text data  
      subject: 'Welcome Beta Tester',
      html:"Hello " + testerName + "! <br><br>" +

    "Thank you for your interest in our app and registering for our beta test! We are very  excited to share our hard work with you and look forward to your feedback." +
  "You can download the latest beta version " + "here".link(distroLink) + "<br><br>
Thank you again, <br> The [Your-App-Name] Team"

}

Send Message

Finally, the message needs to be sent. We pass the send() function our message data. Mailgun will then attempt to send the message. If there is an error, we can display the error page to the user. If the message is successfully sent, we can send a message back to the client telling them they successfully signed up and will be receiving the app. This can be put into an alert box that is displayed. This can also be done when there is an error. You also have the option of rendering a new page letting the tester know they successfully signed up.

1
2
3
4
5
6
7
8
9
10
11
mailgun.messages().send(data, function (err, body) {
        //If there is an error, render the error page
        if (err) {
            res.render('error', { error : err});
            console.log("got an error: ", err);
        }
        //Else send a response letting the tester know they are successfully signed up
        else {
           res.json({"message: Sign up was successful});
        }
    });

The Final Product

Then we put it all together. We now have an automated beta signup and distribution system. This can also be easily integrated into an existing express app.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var express = require('express');
app = express();

var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));

var Mailgun = require("mailgun-js");

Var mailgunKey = YOUR-MAILGUN-API-KEY;

//from your mailgun dashboard
Var domainName = YOUR-DOMAIN.com;

//Email the message will be sent from
Var sendingEmail = your@email.com;

//link to app download provided by crashlytics
Var distroLink = YOUR-URL;

app.post('/signup', function(req, res){
    Var mailgun = new Mailgun({apiKey: mailgunKey, domain: domainName});
    //get name and email
    var testerName = req.body.name;
    var testerEmail = req.body.email;

    //insert into database
    //I leave this to the developer to implement

    //construct message
var data = {
    //Specify email data
      from: sendingEmail,
    //The email to contact
      to: testerEmail,
    //Subject and text data  
      subject: 'Welcome Beta Tester',
      html:"Hello " + testerName + "! <br><br>" +

    "Thank you for your interest in our app and registering for our beta test! We are very  excited to share our hard work with you and look forward to your feedback." +
  "You can download the latest beta version " + "here".link(distroLink) + "<br><br>
Thank you again, <br> The [Your-App-Name] Team"

}

    //send message
mailgun.messages().send(data, function (err, body) {
        //If there is an error, render the error page
        if (err) {
            res.render('error', { error : err});
            console.log("got an error: ", err);
        }
        //Else send a response letting the tester know they are successfully signed up
        else {
           res.json({"message: Sign up was successful});
        }
    });


});