Adrian Bolinger is a Bloc student and has developed three Alexa skills thus far. His most recent, Date Ninja, builds upon Alexa’s ability to convert a spoken date into a slot formatted as a date in order to make day, week, month, and year calculations on the fly.
With each skill, his need to monitor skill performance, optimize, and rollout subsequent releases has been a top priority. Adrian found a simple way to monitor the performance of his Alexa skills, to see which intents are being used and identify invocation issues with intents. He did it using the open source universal-analytics node module, with five lines of code per intent.
Using the Big Nerd Ranch series as a basis, Adrian developed Date Ninja locally with a Node.js environment using the
moment.js library. Installing
with npm, Adrian found the process of implementing Google Analytics to be very easy.
From the terminal in your project’s root directory:
// --save puts it in your package.json file.
npm install universal-analytics --save
Add the following declaration towards the top:
var ua = require('universal-analytics');
1. Create a new account for your skill.
2. Create properties on the skill, ideally one property per intent.
3. Save the ID code (e.g.,
UA-********-*) in a text file for reference later.
Initialize the ua var (which you’ve already declared) within each of your intents.
Adrian planned for three possible outcomes for each intent: a blank value, it works, it fails. He tried to keep the code somewhat generic, so he could cut and paste between intents. He ended up with the following five lines per intent:
// Declare the intentTrackingID's Google Tracking ID
// Make sure this is a locally-scoped var within each intent function.
var intentTrackingID = ua('UA-********-*');
// report a blank value
intentTrackingID.event("invalid request","blank value").send();
// report a success
var requestedData = ("inputDate: " + inputDate + " myVar: " + myVar).toString();
// report a failure
For each intent that’s successfully wired up, Adrian encourages you to test that it’s posted to Google Analytics before starting work on implementing analytics on the next intent. He suggests testing each intent on Amazon’s test server before submitting your skill for certification. This will help you resolve any potential issues that are not exposed when testing on local node server and help you publish your skill quickly.
To get the scoop, read Adrian’s full blog post on implementing Google Analytics.
Share other innovative ways you’re using Alexa in your life. Tweet us @alexadevs with hashtag #AlexaDevStory.