Countly For iOS and Web Analytics

2 minute read

I previously mentioned that I wasn’t too keen on all the things Firebase Crashlytics installed and would look at Countly as an alternative.

Countly is impressive. They have loads of documentation, and support loads of platforms.

They offer a paid Enterprise version or a free Community, self-hosted, option. I went with the Community edition.

The only significant missing feature (for me at least) in the Community version is no symbolication and de-obfuscation of crash traces.

Also, if you’re installing onto a server where you already have Nginx set up, you have to run the install scripts carefully.

Server Installation

They have many install options, including a one-liner install script that downloads the rest of the server and tries to install and configure your server. I did it manually.

Get the latest release and unzip:

LATEST=$(wget -qO- https://api.github.com/repos/countly/countly-server/releases/latest | grep browser_download_url | head -n 1 | cut -d '"' -f 4) ;

echo "Downloading from Github..."
if [[ "$LATEST" == *zip ]]
then
    wget -nv "$LATEST" -O ./countly.zip ;
    unzip countly.zip
else
    wget -nv "$LATEST" -O ./countly.tar.gz ;
    tar zxfv countly.tar.gz ;
fi

Then run the installer script:

DATE=$(date +%Y-%m-%d:%H:%M:%S)
if [[ ! -z "$APT_GET_CMD" ]]; then
    bash countly/bin/countly.install.sh 2>&1 | tee "countly/log/countly-install-$DATE.log"
elif [[ ! -z "$YUM_CMD" ]]; then
    bash countly/bin/countly.install_rhel.sh 2>&1 | tee "countly/log/countly-install-$DATE.log"
else
    echo "error can't install Countly"
    exit 1;
fi

Which, for Ubuntu, calls countly.install_ubuntu.sh

  • Installs build dependencies
  • Installs Node 10
  • Installs Nginx (I skipped this)
  • Installs supervisor
  • Installs grunt & npm modules
  • Installs MongoDB
  • Installs the Countly commands
  • Configures a default site for Nginx (I skipped this)
  • Installs various config files
  • Installs Nghttp2
  • Installs Countly plugins
  • Builds Countly, then starts it.

I had to do a bit of extra faffing to get Let’s Encrypt certificates and plug it into my already configured Nginx setup.

After that you need to:

Then login and create your admin user, create your apps, get the app keys and install the SDK for the apps or Web site you want to monitor.

iOS SDK Installation

Download and install the SDK - just 32 files, all easy to comprehend.

Then instantiate Countly:

CountlyConfig* config = CountlyConfig.new;

config.appKey = kCountlyAPIKey;
config.host = kCountlyEndpoint;
config.features = @[CLYCrashReporting, CLYAutoViewTracking];
config.starRatingDisableAskingForEachAppVersion = YES;
config.secretSalt = kCountlyAPISalt;
config.alwaysUsePOST = YES;

[Countly.sharedInstance startWithConfig:config];

[Countly.sharedInstance disableLocationInfo];

That’s about it. There are many things you can configure on both the SDK and the server. Check the docs for that.

One note of warning, the SDK, by default, uses the Advertising Identifier (IDFA), so you have to tell Apple why you’re using it, or disable it entirely. See the Countly docs.

Web Analytics Installation

You need to either add sdk/web/countly.min.js from your Countly server to your header code for the site you want to track, or grab the file and add it to your site’s build process. That’s what I did.

Added it to assets:

assets

Created a setup html file:

setup

Then added it to my custom scripts _include:

scripts

So I now have some analytics trickling in:

HKWarnings

stouty