Joseph Jude

Technology, Psychology, and Story Telling

Integrating Betaout With A Golang Application

Posted: Tags: golang,wisecrowd

Betaout, is a comprehensive e-marketing suite. You can connect your SAAS app with Betaout and send user events to it, from signup to purchase. Once these events are sent to Betaout, you can measure every metrics for the marketing and sales funnel. You can segment your users (or customers), through variety of filters and email them from within the app. It is a valuable tool for any SAAS owner.

I wanted to integrate Betaout with WiseCrowd. Wisecrowd is an audience engagement tool, I developed, to crowd-source questions from the audience at events. Event organizers can create events and pass the event id to participants. Then participants can login, join the event and ask questions. They can also up vote and down vote questions, so that the best questions are answered at events.

You can send event data using Javascript, which is the usual way. Thankfully, Betaout has a REST API and I used that rather than their Javascript version. Why? Two reasons.

  • I'm weary of exposing anything to front-end browsers. When it comes to security, less is more. Even if you run the entire app on https, you are still dependent on a third party (users) to keep the security model secure.
  • My preferred app architecture is to keep all business logic, and heavy lifting on the server side. In this model, web front-end and mobile app are only presentations(V of MVC). Here, there is no repetition of business logic (like, sending data to Betaout) from different view layers. Additional benefit of this model is a uniform data collection and tagging.

Betaout integration

To integrate with Betaout you need API key and project id. After creating an account and logging in, go grab these keys from API Keys page.

Here is a method to send user events to Betaout.

package base

import (
    "bytes"
    "io/ioutil"
    "net/http"
)

const (
    betaoutAPI = "xxxxxxxxxxxxxxxxx"
    betaoutURL = "https://xxProjectIdxx.betaout.in/v1/user/event"
)

func SendToBetaout(event string, email string) {

    betaParams := []byte(`{"event":"` + event + `", "apiKey":"` + betaoutAPI + `","email":"` + email + `"}`)
    betaParamsInBytes := bytes.NewBuffer(betaParams)

    req, _ := http.NewRequest("POST", betaoutURL, betaParamsInBytes)
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, err := client.Do(req)

    if err != nil {
        fmt.Println(err.Error())
    }

    defer resp.Body.Close()
    body, _ := ioutil.ReadAll(resp.Body)
    fmt.Println(string(body))
}

Last three lines are probably needed while you develop and when you move to production, you should comment them out. You should also include a mechanism to log errors or send to a SAAS service like LogEntries.

Now this method can be invoked from different methods in your application. As an example, whenever a new users signs up, invoke go SendToBetaout("signup", email) to send signup event to Betaout. Or invoke go SendToBetaout(fmt.Sprintf("up_voted_on: %d", entry.Id), user.Email) to register vote event.

If you run a SAAS app, you should definitely checkout Betaout. It is a great tool.


Comments

comments powered by Disqus