Google Analytics

Send events from Dashly to your GA

In this article you'll find two ways of configuring data communication between Google Analytics and your project:

  • via Configure the Javascript code section
  • via Triggered messages section

Sending events via Configure the JavaScript code section

You can do it using JavaScript, . The script can be inserted in the “Settings” – “Visitors data tracking” – "Configure the JavaScript code" section:

Sending "Chat opened" event to GA:

// For GA:
dashly.addCallback('messenger_opened', function(data) {
    ga('send', 'event', 'Dashly', 'ChatOpened');
});

// For GTM:
dashly.addCallback('messenger_opened', function(data) {
    ga.getAll()[0].send('event', 'Dashly', 'ChatOpened');
});

Let’s say you have a triggered message with the ID of 1234. You can find the ID of this message in the search bar of the message settings page:

Sending "PopupSeen" event to GA:

// For GA:
dashly.addCallback('conversation_opened', function(data) {
    if (data.message == '1234') {
        ga('send', 'event', 'Dashly', 'PopupSeen');   }
});

// For GTM:dashly.addCallback('conversation_opened', function(data) {
    if (data.message == '1234') {
        ga.getAll()[0].send('event', 'Dashly', 'PopupSeen');
    }
});

Sending "LeftEmailInPopup" event to GA:

// For GA:
dashly.addCallback('user_replied', function(data) {
    if (data.message == '1234') {
        ga('send', 'event', 'Dashly', 'LeftEmailInPopup');   }
});

// For GTM:
dashly.addCallback('user_replied', function(data) {
    if (data.message == '1234') {
        ga.getAll()[0].send('event', 'Dashly', 'LeftEmailInPopup');
    }
});

Sending “MessageSeen” event to GA:

// For GA:
dashly.addCallback('conversation_opened', function(data) {
    if (data.message) {
      ga('send', 'event', 'Dashly', 'MessageSeen');
    } 
});
// For GTM
dashly.addCallback('conversation_opened', function(data) {
    if (data.message) {
     ga.getAll()[0].send('event', 'Dashly', 'MessageSeen'); 
    } 

Sending any event to GA via Triggered JavaScript

Go to the “Triggered messages” section and create a new message. Choose “JavaScript” as the message type:

Enter this code in the code input field:

ga.getAll()[0].send('event', 'Dashly', 'ConversationStarted');

This code will pass the ConversationStarted event to GA. Unlike the methods described above, we’ll only need one line of code to send an event via a JavaScript message.

To make the code work, you will need to set its trigger. As we’re passing the "ConversationStarted" event in this example, the event we’ll have to use as its trigger is “Communication: User started a chat conversation”:

Then go on to saving the message. The scenario will work like this: user starts a new conversation in chat, thus getting the “Communication: User started a chat conversation” event to record and triggering the JS message, which sends the event to Google Analytics in turn. Using this method, you can send practically any event to GA.

How to send email statistics to Google Analytics

You can send lead's actions (such as opening an email) to Google Analytics and use this data for metrics. Let's see how you can do it.

  1. Create goals in Google Analytics

  2. Create a new message and follow the next steps

  3. Set trigger, audience and sending conditions. In the “Content” tab, open the “Code View”:

  4. Use this code template:

<img src="http://www.google-analytics.com/collect?v=1&tid=UA-XXXXXXX-YY&cid={{user['clientId']}}&t=event&ec=email&ea=open&el=recipient_id&cs=newsletter&cm=email&cn=11" />

Script components explanation:

img src= with this, we make email services think that the email contains an image. In fact there is no image, the inserted address is a GET request which sends information to GA. So when your email sends "an image", it in fact sends data to Google Analytics.

http://www.google-analytics.com/collect? This one is for the Measurement Protocol API. You’ll need to add Tracking ID and goal information to its parameters.

v=1 Protocol version (required)

tid = UA-XXXXXX-YY Tracking ID / Web Property ID (required)

cid = {{user['ClientID']}} user’s Client ID (required)

In order to add the user’s Client ID, you can record it as a custom property and add it to the link. Here’s a code you can record the custom ClientID property with:

function getGCid() {
  var match = document.cookie.match('(?:^|;)\\s*_ga=([^;]*)');
  var raw = (match) ? decodeURIComponent(match[1]) : null;
  if (raw) {
    match = raw.match(/(\d+\.\d+)$/);
  }
  var gacid = (match) ? match[1] : null;
  if (gacid) {
    dashly.identify([{op: 'set_once', key: 'ClientID', value: gacid}]);
  }
};
getGCid();

Paste this script in the “Settings” – “Visitors data tracking” – “Configure the JavaScript code” section

t = event Tracking type

ec = email Event category

ea = open Event action

el = recipient_id Event label (optional);

cs = newsletter Campaign Source (optional)

cm = email Campaign Medium (optional)

cn = 111 Campaign Name (optional)

An example with added parameters:

<img src=”http://www.google-analytics.com/collect?v=1&tid=UA-12345678-1&cid=456&t=event&ec=email&ea=open&el=recipient_id&cs=newsletter&cm=email&cn=11”/>

5. Finish creating the message and launch it.

From now on, when someone opens your email, the metric will be recorded and you will be able to see it in your GA report.

Powered by