Request a Demo Start Trial
JavaScript Analytics
Download JavaScript Analytics SDK
version 2.3.0

Chrome Extensions

This document covers integrating the DeskMetrics analytics SDK into a Chrome Extension. We’ll also walk you through the steps required to setup install attribution from an inline install page.

Get the Library

Download the JavaScript SDK and include the unminified version with your extension’s source files.

Or install using npm:

npm install deskmetrics


Declare a background script including the DeskMetrics SDK followed by your own script(s):

"background": {
    "scripts": [

And the required permissions:

"permissions": [

Background Script

In your background script we’ll start the SDK. Additional properties could be set within a callback passed to the start function.

$dm.start({ 'appId': '<-- YOUR APP ID -->' });

We’re ready to send an event of our own:

$dm.send('hello_world', { 'regards_from': 'background.js' });

The SDK sends the following events out of the box:

Content Script

If you want to send events from a content script, you could do something like this:

chrome.runtime.sendMessage({type: 'analytics', name: 'my_custom_event', body: { ... }});

And add this to your background script:

chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
  if(message.type == 'analytics') {
      $dm.send(, message.body);

Extension Inline Install Attribution

If you integrate DeskMetrics into both your inline install page and Chrome extension, you can configure the extension integration to pickup any properties set from the inline install page.

In practice this means that the properties url, utm_source, utm_medium, etc… we set in the Web Page Integration will make their way onto all events sent from the Chrome Extension Integration.


Declare additional permissions - for your inline install domain as well as cookies and tabs:

"permissions": [

Background Script

Specify the landingPageDomain option when starting the SDK:

var options = {
    'appId': '<-- YOUR APP ID -->',
    'landingPageDomain': ''