Skip to content
Login Contact

Alexa multimedia instrumentation for Marfeel audio tracking

Marfeel tracks audio reproduction in Alexa by integrating with Alexa Custom Skills running in Node.js environments. The @marfeel/compasstrackermultimedia-alexa package hooks into request and response interceptors, enabling automatic audio playback tracking without changes to your existing skill handlers.

Your .npmrc file must include the Marfeel npm registry before installing:

@marfeel:registry=https://repositories-proxy.mrf.io/nexus/repository/npm-all

Run npm install @marfeel/compasstrackermultimedia-alexa to add the package. If you are using the Alexa developer console for building your skill, add the following entry in the package.json dependencies definition:

"dependencies": {
"@marfeel/compasstrackermultimedia-alexa": "^1.0.0-snapshot.22",
},

The @marfeel/compasstrackermultimedia-alexa package integrates with your skill via interceptors. Call getInterceptors with your Marfeel account ID, then attach the returned requestInterceptor and responseInterceptor to your skill builder. This is compatible with the broader Marfeel SDK ecosystem for multi-platform tracking.

const Alexa = require('ask-sdk-core');
const { getInterceptors } = require('@marfeel/compasstrackermultimedia-alexa');
const YOUR_ACCOUNT_ID = 0;
const { requestInterceptor, responseInterceptor } = getInterceptors({ accountId: YOUR_ACCOUNT_ID });
const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
.addRequestHandlers(
// your handlers
)
.addResponseInterceptors(responseInterceptor)
.addRequestInterceptors(requestInterceptor)
.lambda();

The token generated for AudioPlayer serves as the unique media identifier. Different users listening to the same resource should receive the same token, ensuring consistent tracking across sessions.

You can customize this behavior by passing a translator function to getInterceptors:

const Alexa = require('ask-sdk-core');
const { getInterceptors } = require('@marfeel/compasstrackermultimedia-alexa');
const YOUR_ACCOUNT_ID = 0;
const { requestInterceptor, responseInterceptor } = getInterceptors({
accountId: YOUR_ACCOUNT_ID,
translator: yourToken => {
// your logic for retrieving the resource id from yourToken
return resourceId;
}
});

The media title is retrieved from the AudioPlayer.Play metadata directive. By default, audioItem.metadata.title is used. If your metadata title is not the name you want for multimedia tracking, use the mrfTitle field instead:

addAudioPlayerPlayDirective('REPLACE_ALL', stream.url, stream.token, 0, null, {
{
'title': 'Title to display in alexa',
'subtitle': 'Subtitle',
'mrfTitle': `media-name`,
'art': {},
'backgroundImage': {},
});
What is the unique media identifier used by the Marfeel Alexa SDK?

The AudioPlayer token is used as the unique media identifier. Different users listening to the same resource receive the same token. You can customize this behavior by providing a translator function to getInterceptors.

How does the Marfeel Alexa SDK retrieve the media title?

By default, the SDK uses audioItem.metadata.title from the AudioPlayer.Play metadata directive. If you need a different name for tracking, you can set a custom mrfTitle field in the metadata.

How do I install the Marfeel Alexa multimedia tracking package?

Configure your .npmrc to point to Marfeel’s npm registry, then run npm install @marfeel/compasstrackermultimedia-alexa. If you use the Alexa developer console, add the package directly to your package.json dependencies.