Tracking an event

Tracking an event is very easy. In this section you will find some examples using the libraries that we have created for common programming languages. If your language does not appear below, don't worry, you just need to send an HTTP POST request as shown in this section.

To track an event from the browser with JavaScript you will need to:

  1. Make sure you have included the tracking code in every page of your website or application.
  2. Track the event from your JavaScript code with the following line (replace the second argument with the name of your event):
    _dp("track", "Billed");

    You can also attach information related to an event (optional) usign the metadata object:

    _dp("track", "Billed", {
      metadata: {
        amount: 200,
        credits: 5000
      }
    });

    You can also send information about the visitor that executed an event (optional) using the person object:

    _dp("track", "Billed", {
      person: {
        email: "[email protected]",
        user_id: 23,
      },
      metadata: {
        amount: 200,
        credits: 5000
      }
    });

    Read this:

    The JS (Browser) library will identify the visitor who executed an event in your site as a "Guest" by automatically passing the value (pid) of the cookie that ConvertLoop installs in your visitor's browser. Learn more about the dp_pid: pid cookie.

    To turn a "Guest" into a "Contact" you need to pass at least the email of the visitor along with the pid

    Learn more about the attributes of the function to track an event

    Check out some examples and a detailed explanation on ConvertLoop's Event Tracking Guide

To track an event from PHP (using Composer):

  1. Install the library running the following command:
    $ composer require convertloop/convertloop-php
  2. Instantiate the ConvertLoop\ConvertLoop class passing your credentials:
    $convertloop = new \ConvertLoop\ConvertLoop("your_app_id", "your_api_key", "v1");
    You can find your app_id and api_key in Settings -> Account once you are logged in.
  3. Track the Event:
    $contact = array("email" => "[email protected]", "user_id" => 23, "pid" => "8t16f883")
    $convertloop->eventLogs()->send(array("name" => "Your Event Name", "person" => $contact));

Read this:

To identify the visitor that executed the event, you need to pass at least one of the following attributes to the person object: pid, user_id or email.

Use pid when you are identifying who executed an event when they are not logged into your site. You can obtain this value from the cookie dp_pid: pid that ConvertLoop installs in your visitor's browser with your tracking code.

Use user_id to match the id of the user in your application who executed an event whilst logged into your site.

When tracking an event from your backend, we recommend that you send the pid every time that a contact executes the event that you are tracking. This will merge the entire story of the actions executed by each visitor, even those that occurred before you captured their email address for the first time.

We recommend that you send the pid every time a contact logs into your site, to merge the story of the actions executed by that visitor before the login.

Learn more about the attributes of the function to track an event

Check out the PHP API Client for more information.

Check out some examples and a detailed explanation on ConvertLoop's Event Tracking Guide

To track an event from Ruby on Rails:

  1. Install the gem in your Gemfile:
    gem 'convertloop', '0.1.2'
  2. Run bundle install from the command line.
  3. Create a file config/initializers/convertloop.rb and paste the following code:
    ConvertLoop.configure(
      app_id: 'your_app_id',
      api_key: 'your_api_key'
    )
    You can find your app_id and api_key in Settings -> Account once you are logged in.
  4. Track the Event:
    ConvertLoop.event_logs.send(
      name:"Your Event Name",
      person: {
        email: "[email protected]",
        user_id: 23,
        pid: "8t16f883"
      },
      metadata: { credits: 1000 },
      ocurred_at: 1.hour.ago
    )
    

Read this:

To identify the visitor that executed the event, you need to pass at least one of the following attributes to the person object: pid, user_id or email.

Use pid when you are identifying who executed an event when they are not logged into your site. You can obtain this value from the cookie dp_pid: pid that ConvertLoop installs in your visitor's browser with your tracking code.

Use user_id to match the id of the user in your application who executed an event whilst logged into your site.

When tracking an event from your backend, we recommend that you send the pid every time that a contact executes the event that you are tracking. This will merge the entire story of the actions executed by each visitor, even those that occurred before you captured their email address for the first time.

We recommend that you send the pid every time a contact logs into your site, to merge the story of the actions executed by that visitor before the login.

Learn more about the attributes of the function to track an event

Check out the Ruby API Client for more information.

Check out some examples and a detailed explanation on ConvertLoop's Event Tracking Guide

To track an event from Ruby (without bundler):

  1. Install the gem from your command line:
    $ gem install convertloop
  2. Configure the ConvertLoop object passing your credentials.
    require 'convertloop'
    ConvertLoop.configure(
      app_id: 'your_app_id',
      api_key: 'your_api_key'
    )
    
    You can find your app_id and api_key in Settings -> Account once you are logged in.
  3. Track the Event:
    ConvertLoop.event_logs.send(name:"Your Event Name", person: { email: "[email protected]", user_id: 23, pid: "8t16f883" }, metadata: { credits: 1000 }, ocurred_at: 1.hour.ago)
    

Read this:

To identify the visitor that executed the event, you need to pass at least one of the following attributes to the person object: pid, user_id or email.

Use pid when you are identifying who executed an event when they are not logged into your site. You can obtain this value from the cookie dp_pid: pid that ConvertLoop installs in your visitor's browser with your tracking code.

Use user_id to match the id of the user in your application who executed an event whilst logged into your site.

When tracking an event from your backend, we recommend that you send the pid every time that a contact executes the event that you are tracking. This will merge the entire story of the actions executed by each visitor, even those that occurred before you captured their email address for the first time.

We recommend that you send the pid every time a contact logs into your site, to merge the story of the actions executed by that visitor before the login.

Learn more about the attributes of the function to track an event

Check out the Ruby API Client for more information.

Check out some examples and a detailed explanation on ConvertLoop's Event Tracking Guide

To track an event from Node.js:

  1. Install the package from your command line:
    $ npm install convertloop
  2. Configure the ConvertLoop object passing your credentials.
    const Convertloop = require('convertloop')
    const convertloop = new Convertloop({
      app_id: 'your_app_id',
      api_key: 'your_api_key'
    })
    You can find your app_id and api_key in Settings -> Account once you are logged in.
  3. Track the Event:
    convertloop.event_logs.send({
      name:"Your Event Name",
      person: {
        email: "[email protected]",
        user_id: 23,
        pid: "8t16f883"
      },
      metadata: { credits: 1000 },
      ocurred_at: new Date()
    })

Read this:

To identify the visitor that executed the event, you need to pass at least one of the following attributes to the person object: pid, user_id or email.

Use pid when you are identifying who executed an event when they are not logged into your site. You can obtain this value from the cookie dp_pid: pid that ConvertLoop installs in your visitor's browser with your tracking code.

Use user_id to match the id of the user in your application who executed an event whilst logged into your site.

When tracking an event from your backend, we recommend that you send the pid every time that a contact executes the event that you are tracking. This will merge the entire story of the actions executed by each visitor, even those that occurred before you captured their email address for the first time.

We recommend that you send the pid every time a contact logs into your site, to merge the story of the actions executed by that visitor before the login.

Learn more about the attributes of the function to track an event

Check out the Node API Client for more information.

Check out some examples and a detailed explanation on ConvertLoop's Event Tracking Guide

To track an event from Java:

  1. Add the dependency in your pom.xml file:
    <dependency>
      <groupId>co.convertloop</groupId>
      <artifactId>convertloop-java</artifactId>
      <version>0.1.0</version>
    </dependency>
    Or add the dependency in your build.gradle file:
    dependencies {
        compile 'co.convertloop:convertloop-java:0.1.0'
    }
  2. Configure the ConvertLoop object passing your credentials:
    Convertloop convertloop = new Convertloop("your_app_id", "your_api_key", "v1");
    You can find your app_id and api_key in Settings -> Account once you are logged in.
  3. Track the Event:
    HashMap contact = new HashMap();
    contact.put("email", "[email protected]");
    contact.put("user_id", 23);
    contact.put("pid", "8t16f883");
    HashMap metadata = new HashMap();
    metadata.put("credits", 1000);
    HashMap event = new HashMap();
    event.put("name", "Billed");
    event.put("person", contact);
    event.put("metadata", metadata);
    event.put("occurred_at", new Date());
    convertloop.sendEventLog(event);

Read this:

To identify the visitor that executed the event, you need to pass at least one of the following attributes to the person object: pid, user_id or email.

Use pid when you are identifying who executed an event when they are not logged into your site. You can obtain this value from the cookie dp_pid: pid that ConvertLoop installs in your visitor's browser with your tracking code.

Use user_id to match the id of the user in your application who executed an event whilst logged into your site.

When tracking an event from your backend, we recommend that you send the pid every time that a contact executes the event that you are tracking. This will merge the entire story of the actions executed by each visitor, even those that occurred before you captured their email address for the first time.

We recommend that you send the pid every time a contact logs into your site, to merge the story of the actions executed by that visitor before the login.

Learn more about the attributes of the function to track an event

Check out the Java API Client for more information.

Check out some examples and a detailed explanation on ConvertLoop's Event Tracking Guide

To track an event from your command line (Linux or Mac) run the following command (replace the highlighted info with your own data):

$ curl -i -u app_id:api_key \
-X POST \
-H "Content-Type: application/json" \
-d '{ "name": "Signed Up", "person": { "email": "[email protected]"} }' \
https://api.convertloop.co/v1/event_logs
You can find your app_id and api_key in Settings -> Account once you are logged in.

Response

After making the request you should receive a JSON response similar to the following:

{
 "occurred_at" : "2016-12-06T04:57:48.150Z",
 "metadata" : {},
 "person" : {
   "pid" : "27783937",
   "user_id" : null,
   "email" : "[email protected]",
   "name" : "",
   "first_seen_at" : null,
   "last_seen_at" : null,
   "created_at" : "2016-12-06T04:55:30.013Z",
   "tags" : []
 },
 "event" : {
   "slug" : "billed",
   "description" : null
 }
}

Read this:

To identify the visitor that executed the event, you need to pass at least one of the following attributes to the person object: pid, user_id or email.

Use pid when you are identifying who executed an event when they are not logged into your site. You can obtain this value from the cookie dp_pid: pid that ConvertLoop installs in your visitor's browser with your tracking code.

Use user_id to match the id of the user in your application who executed an event whilst logged into your site.

When tracking an event from your backend, we recommend that you send the pid every time that a contact executes the event that you are tracking. This will merge the entire story of the actions executed by each visitor, even those that occurred before you captured their email address for the first time.

We recommend that you send the pid every time a contact logs into your site, to merge the story of the actions executed by that visitor before the login.

Learn more about the attributes of the function to track an event

Check out some examples and a detailed explanation on ConvertLoop's Event Tracking Guide