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:
_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
}
});
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):
$ composer require convertloop/convertloop-php
ConvertLoop\ConvertLoop
class passing your credentials:
$convertloop = new \ConvertLoop\ConvertLoop("your_app_id", "your_api_key", "v1");
$contact = array("email" => "[email protected]", "user_id" => 23, "pid" => "8t16f883")
$convertloop->eventLogs()->send(array("name" => "Your Event Name", "person" => $contact));
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
To track an event from Ruby on Rails:
gem 'convertloop', '0.1.2'
bundle install
from the command line.config/initializers/convertloop.rb
and paste the following code:
ConvertLoop.configure(
app_id: 'your_app_id',
api_key: 'your_api_key'
)
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
)
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
To track an event from Ruby (without bundler):
$ gem install convertloop
require 'convertloop'
ConvertLoop.configure(
app_id: 'your_app_id',
api_key: 'your_api_key'
)
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)
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
To track an event from Node.js:
$ npm install convertloop
const Convertloop = require('convertloop')
const convertloop = new Convertloop({
app_id: 'your_app_id',
api_key: 'your_api_key'
})
convertloop.event_logs.send({
name:"Your Event Name",
person: {
email: "[email protected]",
user_id: 23,
pid: "8t16f883"
},
metadata: { credits: 1000 },
ocurred_at: new Date()
})
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
To track an event from Java:
<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'
}
Convertloop convertloop = new Convertloop("your_app_id", "your_api_key", "v1");
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);
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
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
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
}
}
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