You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@unomi.apache.org by sh...@apache.org on 2018/11/05 14:08:37 UTC

svn commit: r1845794 [17/19] - in /incubator/unomi/website/manual: 1_1_x/ 1_1_x/images/ 1_2_x/ 1_2_x/connectors/ 1_2_x/images/ 1_2_x/samples/ 1_3_x/ 1_3_x/asciidoc/ 1_3_x/connectors/ 1_3_x/images/ 1_3_x/samples/ latest/ latest/connectors/ latest/images...

Added: incubator/unomi/website/manual/latest/index.html
URL: http://svn.apache.org/viewvc/incubator/unomi/website/manual/latest/index.html?rev=1845794&view=auto
==============================================================================
--- incubator/unomi/website/manual/latest/index.html (added)
+++ incubator/unomi/website/manual/latest/index.html Mon Nov  5 14:08:37 2018
@@ -0,0 +1,3233 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="UTF-8">
+<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
+<meta name="generator" content="Asciidoctor 1.5.6.1">
+<meta name="author" content="Apache Software Foundation">
+<title>Apache Unomi 1.x - Documentation</title>
+<link rel="stylesheet" href="./apache.css">
+</head>
+<body class="article toc2 toc-left">
+<div id="header">
+<h1>Apache Unomi 1.x - Documentation</h1>
+<div class="details">
+<span id="author" class="author">Apache Software Foundation</span><br>
+</div>
+<div id="toc" class="toc2">
+<div id="toctitle">Table of Contents</div>
+<ul class="sectlevel1">
+<li><a href="#_quick_start">1. Quick start</a>
+<ul class="sectlevel3">
+<li><a href="#_five_minutes_quickstart">1.1. Five Minutes QuickStart</a></li>
+</ul>
+</li>
+<li><a href="#_concepts">2. Concepts</a>
+<ul class="sectlevel2">
+<li><a href="#_items_and_types">2.1. Items and types</a></li>
+<li><a href="#_events">2.2. Events</a></li>
+<li><a href="#_profiles">2.3. Profiles</a></li>
+<li><a href="#_sessions">2.4. Sessions</a></li>
+</ul>
+</li>
+<li><a href="#_setup">3. Setup</a>
+<ul class="sectlevel2">
+<li><a href="#_getting_started_with_unomi">3.1. Getting started with Unomi</a>
+<ul class="sectlevel3">
+<li><a href="#_prerequisites">3.1.1. Prerequisites</a></li>
+<li><a href="#_running_unomi">3.1.2. Running Unomi</a></li>
+<li><a href="#_web_tracker">3.1.3. Web Tracker</a></li>
+</ul>
+</li>
+<li><a href="#_configuration">3.2. Configuration</a>
+<ul class="sectlevel3">
+<li><a href="#_changing_the_default_configuration">3.2.1. Changing the default configuration</a></li>
+<li><a href="#_secured_events_configuration">3.2.2. Secured events configuration</a></li>
+<li><a href="#_installing_the_maxmind_geoiplite2_ip_lookup_database">3.2.3. Installing the MaxMind GeoIPLite2 IP lookup database</a></li>
+<li><a href="#_installing_geonames_database">3.2.4. Installing Geonames database</a></li>
+<li><a href="#_rest_api_security">3.2.5. REST API Security</a></li>
+<li><a href="#_automatic_profile_merging">3.2.6. Automatic profile merging</a></li>
+<li><a href="#_securing_a_production_environment">3.2.7. Securing a production environment</a></li>
+<li><a href="#_integrating_with_an_apache_http_web_server">3.2.8. Integrating with an Apache HTTP web server</a></li>
+<li><a href="#_changing_the_default_tracking_location">3.2.9. Changing the default tracking location</a></li>
+<li><a href="#_apache_karaf_ssh_console">3.2.10. Apache Karaf SSH Console</a></li>
+<li><a href="#_elasticsearch_x_pack_support">3.2.11. ElasticSearch X-Pack Support</a></li>
+</ul>
+</li>
+<li><a href="#_important">3.3. Important !</a></li>
+<li><a href="#_installation_steps">3.4. Installation steps</a></li>
+</ul>
+</li>
+<li><a href="#_integration_samples">4. Integration samples</a>
+<ul class="sectlevel2">
+<li><a href="#_samples">4.1. Samples</a></li>
+<li><a href="#_login_samples">4.2. Login samples</a>
+<ul class="sectlevel3">
+<li><a href="#_warning">4.2.1. Warning !</a></li>
+<li><a href="#_installing_the_samples">4.2.2. Installing the samples</a></li>
+</ul>
+</li>
+<li><a href="#_twitter_samples">4.3. Twitter samples</a>
+<ul class="sectlevel3">
+<li><a href="#_overview">4.3.1. Overview</a></li>
+<li><a href="#_interacting_with_the_context_server">4.3.2. Interacting with the context server</a></li>
+<li><a href="#_retrieving_context_information_from_unomi_using_the_context_servlet">4.3.3. Retrieving context information from Unomi using the context servlet</a></li>
+</ul>
+</li>
+<li><a href="#_example">4.4. Example</a>
+<ul class="sectlevel3">
+<li><a href="#_html_page">4.4.1. HTML page</a></li>
+<li><a href="#_javascript">4.4.2. Javascript</a></li>
+</ul>
+</li>
+<li><a href="#_conclusion">4.5. Conclusion</a></li>
+<li><a href="#_annex">4.6. Annex</a></li>
+<li><a href="#_weather_update_samples">4.7. Weather update samples</a></li>
+</ul>
+</li>
+<li><a href="#_connectors">5. Connectors</a>
+<ul class="sectlevel2">
+<li><a href="#_connectors_2">5.1. Connectors</a>
+<ul class="sectlevel3">
+<li><a href="#_call_for_contributors">5.1.1. Call for contributors</a></li>
+</ul>
+</li>
+<li><a href="#_apache_unomi_salesforce_connector">5.2. Apache Unomi Salesforce Connector</a>
+<ul class="sectlevel3">
+<li><a href="#_getting_started_2">5.2.1. Getting started</a></li>
+<li><a href="#_upgrading_the_salesforce_connectors">5.2.2. Upgrading the Salesforce connectors</a></li>
+<li><a href="#_using_the_salesforce_workbench_for_testing_rest_api">5.2.3. Using the Salesforce Workbench for testing REST API</a></li>
+<li><a href="#_setting_up_streaming_push_queries">5.2.4. Setting up Streaming Push queries</a></li>
+<li><a href="#_executing_the_unit_tests">5.2.5. Executing the unit tests</a></li>
+</ul>
+</li>
+</ul>
+</li>
+<li><a href="#_cluster_setup">6. Cluster setup</a>
+<ul class="sectlevel2">
+<li><a href="#_cluster_setup_2">6.1. Cluster setup</a>
+<ul class="sectlevel3">
+<li><a href="#_2_nodes_configuration">6.1.1. 2 nodes configuration</a></li>
+<li><a href="#_3_nodes_configuration">6.1.2. 3 nodes configuration</a></li>
+</ul>
+</li>
+</ul>
+</li>
+<li><a href="#_consent_api">7. Consent API</a>
+<ul class="sectlevel2">
+<li><a href="#_consent_api_2">7.1. Consent API</a>
+<ul class="sectlevel3">
+<li><a href="#_profiles_with_consents">7.1.1. Profiles with consents</a></li>
+<li><a href="#_consent_type_definitions">7.1.2. Consent type definitions</a></li>
+<li><a href="#_creating_update_a_visitor_consent">7.1.3. Creating / update a visitor consent</a></li>
+<li><a href="#_how_it_works_internally">7.1.4. How it works (internally)</a></li>
+</ul>
+</li>
+</ul>
+</li>
+<li><a href="#_developers">8. Developers</a>
+<ul class="sectlevel2">
+<li><a href="#_building">8.1. Building</a>
+<ul class="sectlevel3">
+<li><a href="#_initial_setup">8.1.1. Initial Setup</a></li>
+<li><a href="#_building_2">8.1.2. Building</a></li>
+<li><a href="#_installing_an_elasticsearch_server">8.1.3. Installing an ElasticSearch server</a></li>
+<li><a href="#_deploying_the_generated_binary_package">8.1.4. Deploying the generated binary package</a></li>
+<li><a href="#_deploying_into_an_existing_karaf_server">8.1.5. Deploying into an existing Karaf server</a></li>
+<li><a href="#_jdk_selection_on_mac_os_x">8.1.6. JDK Selection on Mac OS X</a></li>
+<li><a href="#_running_the_integration_tests">8.1.7. Running the integration tests</a></li>
+<li><a href="#_running_the_performance_tests">8.1.8. Running the performance tests</a></li>
+<li><a href="#_testing_with_an_example_page">8.1.9. Testing with an example page</a></li>
+</ul>
+</li>
+<li><a href="#_types_vs_instances">8.2. Types vs. instances</a></li>
+<li><a href="#_plugin_structure">8.3. Plugin structure</a></li>
+<li><a href="#_extension_points">8.4. Extension points</a>
+<ul class="sectlevel3">
+<li><a href="#_actiontype">8.4.1. ActionType</a></li>
+<li><a href="#_conditiontype">8.4.2. ConditionType</a></li>
+<li><a href="#_persona">8.4.3. Persona</a></li>
+<li><a href="#_propertymergestrategytype">8.4.4. PropertyMergeStrategyType</a></li>
+<li><a href="#_propertytype">8.4.5. PropertyType</a></li>
+<li><a href="#_rule">8.4.6. Rule</a></li>
+<li><a href="#_scoring">8.4.7. Scoring</a></li>
+<li><a href="#_segments">8.4.8. Segments</a></li>
+<li><a href="#_tag">8.4.9. Tag</a></li>
+<li><a href="#_valuetype">8.4.10. ValueType</a></li>
+</ul>
+</li>
+<li><a href="#_other_unomi_entities">8.5. Other Unomi entities</a>
+<ul class="sectlevel3">
+<li><a href="#_userlist">8.5.1. UserList</a></li>
+<li><a href="#_goal">8.5.2. Goal</a></li>
+<li><a href="#_campaign">8.5.3. Campaign</a></li>
+</ul>
+</li>
+<li><a href="#_custom_extensions">8.6. Custom extensions</a>
+<ul class="sectlevel3">
+<li><a href="#_creating_an_extension">8.6.1. Creating an extension</a></li>
+<li><a href="#_deployment_and_custom_definition">8.6.2. Deployment and custom definition</a></li>
+<li><a href="#_predefined_segments">8.6.3. Predefined segments</a></li>
+<li><a href="#_predefined_rules">8.6.4. Predefined rules</a></li>
+<li><a href="#_predefined_properties">8.6.5. Predefined properties</a></li>
+<li><a href="#_predefined_child_conditions">8.6.6. Predefined child conditions</a></li>
+<li><a href="#_predefined_personas">8.6.7. Predefined personas</a></li>
+<li><a href="#_custom_actions">8.6.8. Custom actions</a></li>
+<li><a href="#_custom_conditions">8.6.9. Custom conditions</a></li>
+<li><a href="#_migration_patches">8.6.10. Migration patches</a></li>
+</ul>
+</li>
+</ul>
+</li>
+</ul>
+</div>
+</div>
+<div id="content">
+<div id="preamble">
+<div class="sectionbody">
+<div class="imageblock" style="text-align: center">
+<div class="content">
+<img src="images/incubator-logo.png" alt="incubator logo">
+</div>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_quick_start">1. Quick start</h2>
+<div class="sectionbody">
+<div class="sect3">
+<h4 id="_five_minutes_quickstart">1.1. Five Minutes QuickStart</h4>
+<div class="paragraph">
+<p>1) Install JDK 8 (<a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html" class="bare">http://www.oracle.com/technetwork/java/javase/downloads/index.html</a>) and make sure you set the
+JAVA_HOME variable <a href="https://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t/" class="bare">https://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t/</a></p>
+</div>
+<div class="paragraph">
+<p>2) Download ElasticSearch here : <a href="https://www.elastic.co/downloads/past-releases/elasticsearch-5-6-3" class="bare">https://www.elastic.co/downloads/past-releases/elasticsearch-5-6-3</a> (please &lt;strong&gt;make sure&lt;/strong&gt; you use the proper version : 5.6.3)</p>
+</div>
+<div class="paragraph">
+<p>3) Uncompress it and change the <code>config/elasticsearch.yml</code> to include the following config : &lt;code&gt;cluster.name: contextElasticSearch&lt;/code&gt;</p>
+</div>
+<div class="paragraph">
+<p>4) Launch ElasticSearch using : <code>bin/elasticsearch</code></p>
+</div>
+<div class="paragraph">
+<p>5) Download Apache Unomi here : <a href="http://unomi.incubator.apache.org/download.html" class="bare">http://unomi.incubator.apache.org/download.html</a></p>
+</div>
+<div class="paragraph">
+<p>6) Start it using : <code>./bin/karaf</code></p>
+</div>
+<div class="paragraph">
+<p>7) Start the Apache Unomi packages using <code>unomi:start</code> in the Apache Karaf Shell</p>
+</div>
+<div class="paragraph">
+<p>8) Wait for startup to complete</p>
+</div>
+<div class="paragraph">
+<p>9) Try accessing <a href="https://localhost:9443/cxs/cluster" class="bare">https://localhost:9443/cxs/cluster</a> with username/password: <code>karaf/karaf</code> . You might get a certificate warning in your browser, just accept it despite the warning it is safe.</p>
+</div>
+<div class="paragraph">
+<p>10) Request your first context by simply accessing : <a href="http://localhost:8181/context.js?sessionId=1234" class="bare">http://localhost:8181/context.js?sessionId=1234</a></p>
+</div>
+<div class="paragraph">
+<p>11) If something goes wrong, you should check the logs in <code>./data/log/karaf.log</code>. If you get errors on ElasticSearch,
+make sure you are using the proper version.</p>
+</div>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_concepts">2. Concepts</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>Apache Unomi gathers information about users actions, information that is processed and stored by Unomi services. The collected information can then be used to personalize content, derive insights on user behavior, categorize the user profiles into segments along user-definable dimensions or acted upon by algorithms.</p>
+</div>
+<div class="sect2">
+<h3 id="_items_and_types">2.1. Items and types</h3>
+<div class="paragraph">
+<p>Unomi structures the information it collects using the concept of <code>Item</code> which provides the base information (an identifier and a type) the context server needs to process and store the data. Items are persisted according to their type (structure) and identifier (identity). This base structure can be extended, if needed, using properties in the form of key-value pairs.</p>
+</div>
+<div class="paragraph">
+<p>These properties are further defined by the <code>Item</code>’s type definition which explicits the <code>Item</code>’s structure and semantics. By defining new types, users specify which properties (including the type of values they accept) are available to items of that specific type.</p>
+</div>
+<div class="paragraph">
+<p>Unomi defines default value types: <code>date</code>, <code>email</code>, <code>integer</code> and <code>string</code>, all pretty self-explanatory. While you can think of these value types as "primitive" types, it is possible to extend Unomi by providing additional value types.</p>
+</div>
+<div class="paragraph">
+<p>Additionally, most items are also associated to a scope, which is a concept that Unomi uses to group together related items. A given scope is represented in Unomi by a simple string identifier and usually represents an application or set of applications from which Unomi gathers data, depending on the desired analysis granularity. In the context of web sites, a scope could, for example, represent a site or family of related sites being analyzed. Scopes allow clients accessing the context server to filter data to only see relevant data.</p>
+</div>
+<div class="paragraph">
+<p><em>Base <code>Item</code> structure:</em></p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code class="language-json" data-lang="json">{
+  "itemType": &lt;type of the item&gt;,
+  "scope": &lt;scope&gt;,
+  "itemId": &lt;item identifier&gt;,
+  "properties": &lt;optional properties&gt;
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Some types can be dynamically defined at runtime by calling to the REST API while other extensions are done via Unomi plugins. Part of extending Unomi, therefore, is a matter of defining new types and specifying which kind of Unomi entity (e.g. profiles) they can be affected to. For example, the following JSON document can be passed to Unomi to declare a new property type identified (and named) <code>tweetNb</code>, tagged with the <code>social</code> tag, targeting profiles and using the <code>integer</code> value type.</p>
+</div>
+<div class="paragraph">
+<p><em>Example JSON type definition:</em></p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code class="language-json" data-lang="json">{
+    "itemId": "tweetNb",
+    "itemType": "propertyType",
+    "metadata": {
+        "id": "tweetNb",
+        "name": "tweetNb",
+        "systemTags": ["social"]
+    },
+    "target": "profiles",
+    "type": "integer"
+}</code></pre>
+</div>
+</div>
+<div class="quoteblock">
+<blockquote>
+<div class="paragraph">
+<p>Unomi defines a built-in scope (called <code>systemscope</code>) that clients can use to share data across scopes.</p>
+</div>
+</blockquote>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_events">2.2. Events</h3>
+<div class="paragraph">
+<p>Users' actions are conveyed from clients to the context server using events. Of course, the required information depends on what is collected and users' interactions with the observed systems but events minimally provide a type, a scope and source and target items. Additionally, events are timestamped. Conceptually, an event can be seen as a sentence, the event&#8217;s type being the verb, the source the subject and the target the object.</p>
+</div>
+<div class="paragraph">
+<p><em>Event structure:</em></p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code class="language-json" data-lang="json">{
+    "eventType": &lt;type of the event&gt;,
+    "scope": &lt;scope of the event&gt;,
+    "source": &lt;Item&gt;,
+    "target": &lt;Item&gt;,
+    "properties": &lt;optional properties&gt;
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Source and target can be any Unomi item but are not limited to them. In particular, as long as they can be described using properties and Unomi’s type mechanism and can be processed either natively or via extension plugins, source and target can represent just about anything. Events can also be triggered as part of Unomi’s internal processes for example when a rule is triggered.</p>
+</div>
+<div class="paragraph">
+<p>Events are sent to Unomi from client applications using the JSON format and a typical page view event from a web site could look something like the following:</p>
+</div>
+<div class="paragraph">
+<p><em>Example page view event:</em></p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code class="language-json" data-lang="json">{
+    "eventType": "view",
+    "scope": "ACMESPACE",
+    "source": {
+        "itemType": "site",
+        "scope": "ACMESPACE",
+        "itemId": "c4761bbf-d85d-432b-8a94-37e866410375"
+    },
+    "target": {
+        "itemType": "page",
+        "scope": "ACMESPACE",
+        "itemId": "b6acc7b3-6b9d-4a9f-af98-54800ec13a71",
+        "properties": {
+            "pageInfo": {
+            "pageID": "b6acc7b3-6b9d-4a9f-af98-54800ec13a71",
+            "pageName": "Home",
+            "pagePath": "/sites/ACMESPACE/home",
+            "destinationURL": "http://localhost:8080/sites/ACMESPACE/home.html",
+            "referringURL": "http://localhost:8080/",
+            "language": "en"
+        },
+        "category": {},
+        "attributes": {}
+      }
+    }
+}</code></pre>
+</div>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_profiles">2.3. Profiles</h3>
+<div class="paragraph">
+<p>By processing events, Unomi progressively builds a picture of who the user is and how they behave. This knowledge is embedded in <code>Profile</code> object. A profile is an <code>Item</code> with any number of properties and optional segments and scores. Unomi provides default properties to cover common data (name, last name, age, email, etc.) as well as default segments to categorize users. Unomi users are, however, free and even encouraged to create additional properties and segments to better suit their needs.</p>
+</div>
+<div class="paragraph">
+<p>Contrary to other Unomi items, profiles are not part of a scope since we want to be able to track the associated user across applications. For this reason, data collected for a given profile in a specific scope is still available to any scoped item that accesses the profile information.</p>
+</div>
+<div class="paragraph">
+<p>It is interesting to note that there is not necessarily a one to one mapping between users and profiles as users can be captured across applications and different observation contexts. As identifying information might not be available in all contexts in which data is collected, resolving profiles to a single physical user can become complex because physical users are not observed directly. Rather, their portrait is progressively patched together and made clearer as Unomi captures more and more traces of their actions. Unomi will merge related profiles as soon as collected data permits positive association between distinct profiles, usually as a result of the user performing some identifying action in a context where the user hadn’t already been positively identified.</p>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_sessions">2.4. Sessions</h3>
+<div class="paragraph">
+<p>A session represents a time-bounded interaction between a user (via their associated profile) and a Unomi-enabled application. A session represents the sequence of actions the user performed during its duration. For this reason, events are associated with the session during which they occurred. In the context of web applications, sessions are usually linked to HTTP sessions.</p>
+</div>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_setup">3. Setup</h2>
+<div class="sectionbody">
+<div class="sect2">
+<h3 id="_getting_started_with_unomi">3.1. Getting started with Unomi</h3>
+<div class="paragraph">
+<p>We will first get you up and running with an example. We will then lift the corner of the cover somewhat and explain in greater details what just happened.</p>
+</div>
+<div class="sect3">
+<h4 id="_prerequisites">3.1.1. Prerequisites</h4>
+<div class="paragraph">
+<p>This document assumes that you are already familiar with Unomi&#8217;s <a href="concepts.html">concepts</a>. On the technical side, we also assume working knowledge of <a href="https://git-scm.com/">git</a> to be able to retrieve the code for Unomi and the example. Additionnally, you will require a working Java 7 or above install. Refer to <a href="http://www.oracle.com/technetwork/java/javase/">http://www.oracle.com/technetwork/java/javase/</a> for details on how to download and install Java SE 7 or greater.</p>
+</div>
+</div>
+<div class="sect3">
+<h4 id="_running_unomi">3.1.2. Running Unomi</h4>
+<div class="sect4">
+<h5 id="_start_unomi">Start Unomi</h5>
+<div class="paragraph">
+<p>Start Unomi according to the <a href="5-min-quickstart.html">5 minute quick start</a> or by compiling using the building <a href="building-and-deploying.html#Deploying_the_generated_package">instructions</a>. Once you have Karaf running,
+ you should wait until you see the following messages on the Karaf console:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>Initializing user list service endpoint...
+Initializing geonames service endpoint...
+Initializing segment service endpoint...
+Initializing scoring service endpoint...
+Initializing campaigns service endpoint...
+Initializing rule service endpoint...
+Initializing profile service endpoint...
+Initializing cluster service endpoint...</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>This indicates that all the Unomi services are started and ready to react to requests. You can then open a browser and go to <code><a href="http://localhost:8181/cxs" class="bare">http://localhost:8181/cxs</a></code> to see the list of
+available RESTful services or retrieve an initial context at <code><a href="http://localhost:8181/context.json" class="bare">http://localhost:8181/context.json</a></code> (which isn&#8217;t very useful at this point).</p>
+</div>
+</div>
+<div class="sect4">
+<h5 id="_request_examples">Request examples</h5>
+<div class="sect5">
+<h6 id="_retrieving_your_first_context">Retrieving your first context</h6>
+<div class="paragraph">
+<p>You can retrieve a context using curl like this :</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>curl http://localhost:8181/context.js?sessionId=1234</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>This will retrieve a JavaScript script that contains a <code>cxs</code> object that contains the context with the current user
+profile, segments, scores as well as functions that makes it easier to perform further requests (such as collecting
+events using the cxs.collectEvents() function).</p>
+</div>
+</div>
+<div class="sect5">
+<h6 id="_retrieving_a_context_as_a_json_object">Retrieving a context as a JSON object.</h6>
+<div class="paragraph">
+<p>If you prefer to retrieve a pure JSON object, you can simply use a request formed like this:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>curl http://localhost:8181/context.json?sessionId=1234</code></pre>
+</div>
+</div>
+</div>
+<div class="sect5">
+<h6 id="_accessing_profile_properties_in_a_context">Accessing profile properties in a context</h6>
+<div class="paragraph">
+<p>By default, in order to optimize the amount of data sent over the network, Apache Unomi will not send the content of
+the profile or session properties. If you need this data, you must send a JSON object to configure the resulting output
+of the context.js(on) servlet.</p>
+</div>
+<div class="paragraph">
+<p>Here is an example that will retrieve all the session and profile properties.</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>curl -H "Content-Type: application/json" -X POST -d '{"source":{"itemId":"homepage","itemType":"page","scope":"example"},"requiredProfileProperties":["*"],"requiredSessionProperties":["*"],"requireSegments":true}' http://localhost:8181/context.json?sessionId=1234</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>The <code>requiredProfileProperties</code> and <code>requiredSessionProperties</code> are properties that take an array of property names
+that should be retrieved. In this case we use the wildcard character '*' to say we want to retrieve all the available
+properties. The structure of the JSON object that you should send is a JSON-serialized version of the <a href="http://unomi.incubator.apache.org/unomi-api/apidocs/org/apache/unomi/api/ContextRequest.html">ContextRequest</a>
+Java class.</p>
+</div>
+</div>
+<div class="sect5">
+<h6 id="_sending_events_using_the_context_servlet">Sending events using the context servlet</h6>
+<div class="paragraph">
+<p>At the same time as you are retrieving the context, you can also directly send events in the ContextRequest object as
+illustrated in the following example:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>curl -H "Content-Type: application/json" -X POST -d '{"source":{"itemId":"homepage","itemType":"page","scope":"example"},"events":[{"eventType":"view","scope": "example","source":{"itemType": "site","scope":"example","itemId": "mysite"},"target":{"itemType":"page","scope":"example","itemId":"homepage","properties":{"pageInfo":{"referringURL":""}}}}]}' http://localhost:8181/context.json?sessionId=1234</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Upon received events, Apache Unomi will execute all the rules that match the current context, and return an updated context.
+This way of sending events is usually used upon first loading of a page. If you want to send events after the page has
+finished loading you could either do a second call and get an updating context, or if you don&#8217;t need the context and want
+to send events in a network optimal way you can use the eventcollector servlet (see below).</p>
+</div>
+</div>
+<div class="sect5">
+<h6 id="_sending_events_using_the_eventcollector_servlet">Sending events using the eventcollector servlet</h6>
+<div class="paragraph">
+<p>If you only need to send events without retrieving a context, you should use the eventcollector servlet that is optimized
+respond quickly and minimize network traffic. Here is an example of using this servlet:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>curl -H "Content-Type: application/json" -X POST -d '{"events":[{"eventType":"view","scope": "example","source":{"itemType": "site","scope":"example","itemId": "mysite"},"target":{"itemType":"page","scope":"example","itemId":"homepage","properties":{"pageInfo":{"referringURL":""}}}}]}' http://localhost:8181/eventcollector?sessionId=1234</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Note that the eventcollector executes the rules but does not return a context. If is generally used after a page is loaded
+to send additional events.</p>
+</div>
+</div>
+</div>
+<div class="sect4">
+<h5 id="_where_to_go_from_here">Where to go from here</h5>
+<div class="ulist">
+<ul>
+<li>
+<p>Read the <a href="twitter-samples.html">Twitter samples</a> documentation that contains a detailed example of how to integrate with Apache Unomi.</p>
+</li>
+</ul>
+</div>
+</div>
+</div>
+<div class="sect3">
+<h4 id="_web_tracker">3.1.3. Web Tracker</h4>
+<div class="paragraph">
+<p>This extension is providing the web tracker to start collecting visitors data on your website.
+The tracker is implemented as an integration of <a href="https://github.com/segmentio/analytics.js">analytics.js</a> for Unomi.</p>
+</div>
+<div class="sect4">
+<h5 id="_getting_started">Getting started</h5>
+<div class="paragraph">
+<p>Extension can be tested at : <code><a href="http://localhost:8181/tracker/index.html" class="bare">http://localhost:8181/tracker/index.html</a></code></p>
+</div>
+<div class="paragraph">
+<p>In your page include unomiOptions and include code snippet from <code>snippet.min.js</code> :</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>&lt;script type="text/javascript"&gt;
+        var unomiOption = {
+            scope: 'realEstateManager',
+            url: 'http://localhost:8181'
+        };
+        window.unomiTracker||(window.unomiTracker={}),function(){function e(e){for(unomiTracker.initialize({"Apache Unomi":unomiOption});n.length&gt;0;){var r=n.shift(),t=r.shift();unomiTracker[t]&amp;&amp;unomiTracker[t].apply(unomiTracker,r)}}for(var n=[],r=["trackSubmit","trackClick","trackLink","trackForm","initialize","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on","personalize"],t=0;t&lt;r.length;t++){var i=r[t];window.unomiTracker[i]=function(e){return function(){var r=Array.prototype.slice.call(arguments);return r.unshift(e),n.push(r),window.unomiTracker}}(i)}unomiTracker.load=function(){var n=document.createElement("script");n.type="text/javascript",n.async=!0,n.src=unomiOption.url+"/tracker/unomi-tracker.min.js",n.addEventListener?n.addEventListener("load",function(n){"function"==typeof e&amp;&amp;e(n)},!1):n.onreadystatechange=function(){"complete"!==this.readyState&amp;&amp;"loaded"!==this.readyState||e(window.event)};var r=
 document.getElementsByTagName("script")[0];r.parentNode.insertBefore(n,r)},document.addEventListener("DOMContentLoaded",unomiTracker.load),unomiTracker.page()}();
+&lt;/script&gt;</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p><code>window.unomiTracker</code> can be used to send additional events when needed.</p>
+</div>
+<div class="paragraph">
+<p>Check analytics.js API <a href="https://segment.com/docs/sources/website/analytics.js/">here</a>.
+All methods can be used on <code>unomiTracker</code> object, although not all event types are supported by Unomi intergation.</p>
+</div>
+</div>
+<div class="sect4">
+<h5 id="_how_to_contribute">How to contribute</h5>
+<div class="paragraph">
+<p>The source code is in the folder javascript with a package.json, the file to update is <code>analytics.js-integration-apache-unomi.js</code> apply your modification in this file then use the command <code>yarn build</code> to compile a new JS file.
+Then you can use the test page to try your changes <code><a href="http://localhost:8181/tracker/index.html" class="bare">http://localhost:8181/tracker/index.html</a></code>.</p>
+</div>
+</div>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_configuration">3.2. Configuration</h3>
+<div class="sect3">
+<h4 id="_changing_the_default_configuration">3.2.1. Changing the default configuration</h4>
+<div class="paragraph">
+<p>If you want to change the default configuration, you can perform any modification you want in the $MY_KARAF_HOME/etc directory.</p>
+</div>
+<div class="paragraph">
+<p>The context server configuration is kept in the $MY_KARAF_HOME/etc/org.apache.unomi.cluster.cfg . It defines the
+addresses where it can be found :</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>contextserver.publicAddress=https://localhost:9443
+contextserver.internalAddress=http://127.0.0.1:8181</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>If you need to specify an Elasticsearch cluster name, or a host and port that are different than the default,
+it is recommended to do this BEFORE you start the server for the first time, or you will loose all the data
+you have stored previously.</p>
+</div>
+<div class="paragraph">
+<p>To change these settings, you will need to modify a file called</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>$MY_KARAF_HOME/etc/org.apache.unomi.persistence.elasticsearch.cfg</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>with the following contents:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>cluster.name=contextElasticSearch
+# The elasticSearchAddresses may be a comma seperated list of host names and ports such as
+# hostA:9300,hostB:9300
+# Note: the port number must be repeated for each host.
+elasticSearchAddresses=localhost:9300
+index.name=context</code></pre>
+</div>
+</div>
+</div>
+<div class="sect3">
+<h4 id="_secured_events_configuration">3.2.2. Secured events configuration</h4>
+<div class="paragraph">
+<p>Unomi secures some events by default. You can find the default configuration in the following file (created after the
+first server startup):</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>$MY_KARAF_HOME/etc/org.apache.unomi.thirdparty.cfg</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Ususally, login events, which operate on profiles and do merge on protected properties, must be secured. For each
+trusted third party server, you need to add these 3 lines :</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>thirdparty.provider1.key=secret-key
+thirdparty.provider1.ipAddresses=127.0.0.1,::1
+thirdparty.provider1.allowedEvents=login,updateProperties</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>The events set in allowedEvents will be secured and will only be accepted if the call comes from the specified IP
+address, and if the secret-key is passed in the X-Unomi-Peer header.</p>
+</div>
+</div>
+<div class="sect3">
+<h4 id="_installing_the_maxmind_geoiplite2_ip_lookup_database">3.2.3. Installing the MaxMind GeoIPLite2 IP lookup database</h4>
+<div class="paragraph">
+<p>The Context Server requires an IP database in order to resolve IP addresses to user location.
+The GeoLite2 database can be downloaded from MaxMind here :
+<a href="http://dev.maxmind.com/geoip/geoip2/geolite2/">http://dev.maxmind.com/geoip/geoip2/geolite2/</a></p>
+</div>
+<div class="paragraph">
+<p>Simply download the GeoLite2-City.mmdb file into the "etc" directory.</p>
+</div>
+</div>
+<div class="sect3">
+<h4 id="_installing_geonames_database">3.2.4. Installing Geonames database</h4>
+<div class="paragraph">
+<p>Context server includes a geocoding service based on the geonames database ( <a href="http://www.geonames.org/">http://www.geonames.org/</a> ). It can be
+used to create conditions on countries or cities.</p>
+</div>
+<div class="paragraph">
+<p>In order to use it, you need to install the Geonames database into . Get the "allCountries.zip" database from here :
+<a href="http://download.geonames.org/export/dump/">http://download.geonames.org/export/dump/</a></p>
+</div>
+<div class="paragraph">
+<p>Download it and put it in the "etc" directory, without unzipping it.
+Edit $MY_KARAF_HOME/etc/org.apache.unomi.geonames.cfg and set request.geonamesDatabase.forceImport to true, import should start right away.
+Otherwise, import should start at the next startup. Import runs in background, but can take about 15 minutes.
+At the end, you should have about 4 million entries in the geonames index.</p>
+</div>
+</div>
+<div class="sect3">
+<h4 id="_rest_api_security">3.2.5. REST API Security</h4>
+<div class="paragraph">
+<p>The Context Server REST API is protected using JAAS authentication and using Basic or Digest HTTP auth.
+By default, the login/password for the REST API full administrative access is "karaf/karaf".</p>
+</div>
+<div class="paragraph">
+<p>The generated package is also configured with a default SSL certificate. You can change it by following these steps :</p>
+</div>
+<div class="paragraph">
+<p>Replace the existing keystore in $MY_KARAF_HOME/etc/keystore by your own certificate :</p>
+</div>
+<div class="paragraph">
+<p><a href="http://wiki.eclipse.org/Jetty/Howto/Configure_SSL">http://wiki.eclipse.org/Jetty/Howto/Configure_SSL</a></p>
+</div>
+<div class="paragraph">
+<p>Update the keystore and certificate password in $MY_KARAF_HOME/etc/custom.properties file :</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>    org.osgi.service.http.secure.enabled = true
+    org.ops4j.pax.web.ssl.keystore=${karaf.etc}/keystore
+    org.ops4j.pax.web.ssl.password=changeme
+    org.ops4j.pax.web.ssl.keypassword=changeme
+    org.osgi.service.http.port.secure=9443</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>You should now have SSL setup on Karaf with your certificate, and you can test it by trying to access it on port 9443.</p>
+</div>
+<div class="olist arabic">
+<ol class="arabic">
+<li>
+<p>Changing the default Karaf password can be done by modifying the etc/users.properties file</p>
+</li>
+</ol>
+</div>
+</div>
+<div class="sect3">
+<h4 id="_automatic_profile_merging">3.2.6. Automatic profile merging</h4>
+<div class="paragraph">
+<p>The context server is capable of merging profiles based on a common property value. In order to use this, you must
+add the MergeProfileOnPropertyAction to a rule (such as a login rule for example), and configure it with the name
+ of the property that will be used to identify the profiles to be merged. An example could be the "email" property,
+ meaning that if two (or more) profiles are found to have the same value for the "email" property they will be merged
+ by this action.</p>
+</div>
+<div class="paragraph">
+<p>Upon merge, the old profiles are marked with a "mergedWith" property that will be used on next profile access to delete
+the original profile and replace it with the merged profile (aka "master" profile). Once this is done, all cookie tracking
+will use the merged profile.</p>
+</div>
+<div class="paragraph">
+<p>To test, simply configure the action in the "login" or "facebookLogin" rules and set it up on the "email" property.
+Upon sending one of the events, all matching profiles will be merged.</p>
+</div>
+</div>
+<div class="sect3">
+<h4 id="_securing_a_production_environment">3.2.7. Securing a production environment</h4>
+<div class="paragraph">
+<p>Before going live with a project, you should <em>absolutely</em> read the following section that will help you setup a proper
+secure environment for running your context server.</p>
+</div>
+<div class="paragraph">
+<p>Step 1: Install and configure a firewall</p>
+</div>
+<div class="paragraph">
+<p>You should setup a firewall around your cluster of context servers and/or Elasticsearch nodes. If you have an
+application-level firewall you should only allow the following connections open to the whole world :</p>
+</div>
+<div class="ulist">
+<ul>
+<li>
+<p><a href="http://localhost:8181/context.js">http://localhost:8181/context.js</a></p>
+</li>
+<li>
+<p><a href="http://localhost:8181/eventcollector">http://localhost:8181/eventcollector</a></p>
+</li>
+</ul>
+</div>
+<div class="paragraph">
+<p>All other ports should not be accessible to the world.</p>
+</div>
+<div class="paragraph">
+<p>For your Context Server client applications (such as the Jahia CMS), you will need to make the following ports
+accessible :</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>8181 (Context Server HTTP port)
+9443 (Context Server HTTPS port)</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>The context server actually requires HTTP Basic Auth for access to the Context Server administration REST API, so it is
+highly recommended that you design your client applications to use the HTTPS port for accessing the REST API.</p>
+</div>
+<div class="paragraph">
+<p>The user accounts to access the REST API are actually routed through Karaf&#8217;s JAAS support, which you may find the
+documentation for here :</p>
+</div>
+<div class="ulist">
+<ul>
+<li>
+<p><a href="http://karaf.apache.org/manual/latest/users-guide/security.html">http://karaf.apache.org/manual/latest/users-guide/security.html</a></p>
+</li>
+</ul>
+</div>
+<div class="paragraph">
+<p>The default username/password is</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>karaf/karaf</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>You should really change this default username/password as soon as possible. To do so, simply modify the following
+file :</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>$MY_KARAF_HOME/etc/users.properties</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>For your context servers, and for any standalone Elasticsearch nodes you will need to open the following ports for proper
+node-to-node communication : 9200 (Elasticsearch REST API), 9300 (Elasticsearch TCP transport)</p>
+</div>
+<div class="paragraph">
+<p>Of course any ports listed here are the default ports configured in each server, you may adjust them if needed.</p>
+</div>
+<div class="paragraph">
+<p>Step 2 : Follow industry recommended best practices for securing Elasticsearch</p>
+</div>
+<div class="paragraph">
+<p>You may find more valuable recommendations here :</p>
+</div>
+<div class="ulist">
+<ul>
+<li>
+<p><a href="https://www.elastic.co/blog/found-elasticsearch-security">https://www.elastic.co/blog/found-elasticsearch-security</a></p>
+</li>
+<li>
+<p><a href="https://www.elastic.co/blog/scripting-security">https://www.elastic.co/blog/scripting-security</a></p>
+</li>
+</ul>
+</div>
+<div class="paragraph">
+<p>Step 4 : Setup a proxy in front of the context server</p>
+</div>
+<div class="paragraph">
+<p>As an alternative to an application-level firewall, you could also route all traffic to the context server through
+a proxy, and use it to filter any communication.</p>
+</div>
+</div>
+<div class="sect3">
+<h4 id="_integrating_with_an_apache_http_web_server">3.2.8. Integrating with an Apache HTTP web server</h4>
+<div class="paragraph">
+<p>If you want to setup an Apache HTTP web server in from of Apache Unomi, here is an example configuration using
+mod_proxy.</p>
+</div>
+<div class="paragraph">
+<p>In your Unomi package directory, in /etc/org.apache.unomi.cluster.cfg for unomi.apache.org</p>
+</div>
+<div class="paragraph">
+<p>contextserver.publicAddress=https://unomi.apache.org/
+ contextserver.internalAddress=http://192.168.1.1:8181</p>
+</div>
+<div class="paragraph">
+<p>and you will also need to change the contextserver.domain in the /etc/org.apache.unomi.web.cfg file</p>
+</div>
+<div class="paragraph">
+<p>contextserver.domain=apache.org</p>
+</div>
+<div class="paragraph">
+<p>Main virtual host config:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>&lt;VirtualHost *:80&gt;
+        Include /var/www/vhosts/unomi.apache.org/conf/common.conf
+&lt;/VirtualHost&gt;
+
+&lt;IfModule mod_ssl.c&gt;
+    &lt;VirtualHost *:443&gt;
+        Include /var/www/vhosts/unomi.apache.org/conf/common.conf
+
+        SSLEngine on
+
+        SSLCertificateFile    /var/www/vhosts/unomi.apache.org/conf/ssl/24d5b9691e96eafa.crt
+        SSLCertificateKeyFile /var/www/vhosts/unomi.apache.org/conf/ssl/apache.org.key
+        SSLCertificateChainFile /var/www/vhosts/unomi.apache.org/conf/ssl/gd_bundle-g2-g1.crt
+
+        &lt;FilesMatch "\.(cgi|shtml|phtml|php)$"&gt;
+                SSLOptions +StdEnvVars
+        &lt;/FilesMatch&gt;
+        &lt;Directory /usr/lib/cgi-bin&gt;
+                SSLOptions +StdEnvVars
+        &lt;/Directory&gt;
+        BrowserMatch "MSIE [2-6]" \
+                nokeepalive ssl-unclean-shutdown \
+                downgrade-1.0 force-response-1.0
+        BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
+
+    &lt;/VirtualHost&gt;
+&lt;/IfModule&gt;</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>common.conf:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>ServerName unomi.apache.org
+ServerAdmin webmaster@apache.org
+
+DocumentRoot /var/www/vhosts/unomi.apache.org/html
+CustomLog /var/log/apache2/access-unomi.apache.org.log combined
+&lt;Directory /&gt;
+        Options FollowSymLinks
+        AllowOverride None
+&lt;/Directory&gt;
+&lt;Directory /var/www/vhosts/unomi.apache.org/html&gt;
+        Options FollowSymLinks MultiViews
+        AllowOverride None
+        Order allow,deny
+        allow from all
+&lt;/Directory&gt;
+&lt;Location /cxs&gt;
+    Order deny,allow
+    deny from all
+    allow from 88.198.26.2
+    allow from www.apache.org
+&lt;/Location&gt;
+
+RewriteEngine On
+RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
+RewriteRule .* - [F]
+ProxyPreserveHost On
+ProxyPass /server-status !
+ProxyPass /robots.txt !
+
+RewriteCond %{HTTP_USER_AGENT} Googlebot [OR]
+RewriteCond %{HTTP_USER_AGENT} msnbot [OR]
+RewriteCond %{HTTP_USER_AGENT} Slurp
+RewriteRule ^.* - [F,L]
+
+ProxyPass / http://localhost:8181/ connectiontimeout=20 timeout=300 ttl=120
+ProxyPassReverse / http://localhost:8181/</code></pre>
+</div>
+</div>
+</div>
+<div class="sect3">
+<h4 id="_changing_the_default_tracking_location">3.2.9. Changing the default tracking location</h4>
+<div class="paragraph">
+<p>When performing localhost requests to Apache Unomi, a default location will be used to insert values into the session
+to make the location-based personalization still work. You can find the default location settings in the file :</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>org.apache.unomi.plugins.request.cfg</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>that contains the following default settings:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code># The following settings represent the default position that is used for localhost requests
+defaultSessionCountryCode=CH
+defaultSessionCountryName=Switzerland
+defaultSessionCity=Geneva
+defaultSessionAdminSubDiv1=2660645
+defaultSessionAdminSubDiv2=6458783
+defaultSessionIsp=Cablecom
+defaultLatitude=46.1884341
+defaultLongitude=6.1282508</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>You might want to change these for testing or for demonstration purposes.</p>
+</div>
+</div>
+<div class="sect3">
+<h4 id="_apache_karaf_ssh_console">3.2.10. Apache Karaf SSH Console</h4>
+<div class="paragraph">
+<p>The Apache Karaf SSH console is available inside Apache Unomi, but the port has been changed from the default value of
+8101 to 8102 to avoid conflicts with other Karaf-based products. So to connect to the SSH console you should use:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>ssh -p 8102 karaf@localhost</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>or the user/password you have setup to protect the system if you have changed it.</p>
+</div>
+</div>
+<div class="sect3">
+<h4 id="_elasticsearch_x_pack_support">3.2.11. ElasticSearch X-Pack Support</h4>
+<div class="paragraph">
+<p>It is now possible to use X-Pack to connect to ElasticSearch. However, for licensing reasons this is not provided out
+of the box. Here is the procedure to install X-Pack with Apache Unomi:</p>
+</div>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_important">3.3. Important !</h3>
+<div class="paragraph">
+<p>Do not start Unomi directly with unomi:start, perform the following steps below first !</p>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_installation_steps">3.4. Installation steps</h3>
+<div class="olist arabic">
+<ol class="arabic">
+<li>
+<p>Create a directory for all the JARs that you will download, we will call it XPACK_JARS_DIRECTORY</p>
+</li>
+<li>
+<p>Download <a href="https://artifacts.elastic.co/maven/org/elasticsearch/client/x-pack-transport/5.6.3/x-pack-transport-5.6.3.jar">https://artifacts.elastic.co/maven/org/elasticsearch/client/x-pack-transport/5.6.3/x-pack-transport-5.6.3.jar</a> to XPACK_JARS_DIRECTORY</p>
+</li>
+<li>
+<p>Download <a href="https://artifacts.elastic.co/maven/org/elasticsearch/plugin/x-pack-api/5.6.3/x-pack-api-5.6.3.jar">https://artifacts.elastic.co/maven/org/elasticsearch/plugin/x-pack-api/5.6.3/x-pack-api-5.6.3.jar</a> to XPACK_JARS_DIRECTORY</p>
+</li>
+<li>
+<p>Download <a href="http://central.maven.org/maven2/com/unboundid/unboundid-ldapsdk/3.2.0/unboundid-ldapsdk-3.2.0.jar">http://central.maven.org/maven2/com/unboundid/unboundid-ldapsdk/3.2.0/unboundid-ldapsdk-3.2.0.jar</a> to XPACK_JARS_DIRECTORY</p>
+</li>
+<li>
+<p>Download <a href="http://central.maven.org/maven2/org/bouncycastle/bcpkix-jdk15on/1.55/bcpkix-jdk15on-1.55.jar">http://central.maven.org/maven2/org/bouncycastle/bcpkix-jdk15on/1.55/bcpkix-jdk15on-1.55.jar</a> to XPACK_JARS_DIRECTORY</p>
+</li>
+<li>
+<p>Download <a href="http://central.maven.org/maven2/org/bouncycastle/bcprov-jdk15on/1.55/bcprov-jdk15on-1.55.jar">http://central.maven.org/maven2/org/bouncycastle/bcprov-jdk15on/1.55/bcprov-jdk15on-1.55.jar</a> to XPACK_JARS_DIRECTORY</p>
+</li>
+<li>
+<p>Download <a href="http://central.maven.org/maven2/com/sun/mail/javax.mail/1.5.3/javax.mail-1.5.3.jar">http://central.maven.org/maven2/com/sun/mail/javax.mail/1.5.3/javax.mail-1.5.3.jar</a> to XPACK_JARS_DIRECTORY
+.</p>
+</li>
+</ol>
+</div>
+<div class="paragraph">
+<p>Edit etc/org.apache.unomi.persistence.elasticsearch.cfg to add the following settings:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>transportClientClassName=org.elasticsearch.xpack.client.PreBuiltXPackTransportClient
+transportClientJarDirectory=XPACK_JARS_DIRECTORY
+transportClientProperties=xpack.security.user=elastic:changeme</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>You can setup more properties (for example for SSL/TLS support) by seperating the properties with commas,
+as in the following example:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>transportClientProperties=xpack.security.user=elastic:changeme,xpack.ssl.key=/home/user/elasticsearch-5.6.3/config/x-pack/localhost/localhost.key,xpack.ssl.certificate=/home/user/elasticsearch-5.6.3/config/x-pack/localhost/localhost.crt,xpack.ssl.certificate_authorities=/home/user/elasticsearch-5.6.3/config/x-pack/ca/ca.crt,xpack.security.transport.ssl.enabled=true</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>.</p>
+</div>
+<div class="paragraph">
+<p>Launch Karaf and launch unomi using the command from the shell :</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>unomi:start</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Alternatively you could edit the configuration directly from the Karaf shell using the following commands:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>config:edit org.apache.unomi.persistence.elasticsearch
+config:property-set transportClientClassName org.elasticsearch.xpack.client.PreBuiltXPackTransportClient
+config:property-set transportClientJarDirectory XPACK_JARS_DIRECTORY
+config:property-set transportClientProperties xpack.security.user=elastic:changeme
+config:update
+unomi:start</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>You can setup more properties (for example for SSL/TLS support) by seperating the properties with commas,
+as in the following example:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>config:property-set transportClientProperties xpack.security.user=elastic:changeme,xpack.ssl.key=/home/user/elasticsearch-5.6.3/config/x-pack/localhost/localhost.key,xpack.ssl.certificate=/home/user/elasticsearch-5.6.3/config/x-pack/localhost/localhost.crt,xpack.ssl.certificate_authorities=/home/user/elasticsearch-5.6.3/config/x-pack/ca/ca.crt,xpack.security.transport.ssl.enabled=true</code></pre>
+</div>
+</div>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_integration_samples">4. Integration samples</h2>
+<div class="sectionbody">
+<div class="sect2">
+<h3 id="_samples">4.1. Samples</h3>
+<div class="paragraph">
+<p>Apache Unomi provides the following samples:</p>
+</div>
+<div class="ulist">
+<ul>
+<li>
+<p><a href="twitter-samples.html">Twitter integration</a></p>
+</li>
+<li>
+<p><a href="login-samples.html">Login integration</a></p>
+</li>
+</ul>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_login_samples">4.2. Login samples</h3>
+<div class="paragraph">
+<p>This samples is an example of what is involved in integrated a login with Apache Unomi.</p>
+</div>
+<div class="sect3">
+<h4 id="_warning">4.2.1. Warning !</h4>
+<div class="paragraph">
+<p>The example code uses client-side Javascript code to send the login event. This is only
+done this way for the sake of samples simplicity but if should NEVER BE DONE THIS WAY in real cases.</p>
+</div>
+<div class="paragraph">
+<p>The login event should always be sent from the server performing the actual login since it must
+only be sent if the user has authenticated properly, and only the authentication server can validate this.</p>
+</div>
+</div>
+<div class="sect3">
+<h4 id="_installing_the_samples">4.2.2. Installing the samples</h4>
+<div class="paragraph">
+<p>Login into the Unomi Karaf SSH shell using something like this :</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>ssh -p 8102 karaf@localhost (default password is karaf)</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Install the login samples using the following command:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>bundle:install mvn:org.apache.unomi/login-integration-samples/${project.version}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>when the bundle is successfully install you will get an bundle ID back we will call it BUNDLE_ID.</p>
+</div>
+<div class="paragraph">
+<p>You can then do:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>bundle:start BUNDLE_ID</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>If all went well you can access the login samples HTML page here :</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>http://localhost:8181/login/index.html</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>You can fill in the form to test it. Note that the hardcoded password is:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>test1234</code></pre>
+</div>
+</div>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_twitter_samples">4.3. Twitter samples</h3>
+<div class="sect3">
+<h4 id="_overview">4.3.1. Overview</h4>
+<div class="paragraph">
+<p>We will examine how a simple HTML page can interact with Unomi to enrich a user&#8217;s profile. The use case we will follow
+is a rather simple one: we use a Twitter button to record the number of times the visitor tweeted (as a <code>tweetNb</code> profile
+integer property) as well as the URLs they tweeted from (as a <code>tweetedFrom</code> multi-valued string profile property).
+A javascript script will use the Twitter API to react to clicks on this button
+and update the user profile using a <code>ContextServlet</code> request triggering a custom event. This event will, in turn,
+trigger a Unomi action on the server implemented using a Unomi plugin, a standard extension point for the server.</p>
+</div>
+<div class="sect4">
+<h5 id="_building_the_tweet_button_samples">Building the tweet button samples</h5>
+<div class="paragraph">
+<p>In your local copy of the Unomi repository and run:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>cd samples/tweet-button-plugin
+mvn clean install</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>This will compile and create the OSGi bundle that can be deployed on Unomi to extend it.</p>
+</div>
+</div>
+<div class="sect4">
+<h5 id="_deploying_the_tweet_button_samples">Deploying the tweet button samples</h5>
+<div class="paragraph">
+<p>In standard Karaf fashion, you will need to copy the samples bundle to your Karaf <code>deploy</code> directory.</p>
+</div>
+<div class="paragraph">
+<p>If you are using the packaged version of Unomi (as opposed to deploying it to your own Karaf version), you can simply run, assuming your current directory is <code>samples/tweet-button-plugin</code> and that you uncompressed the archive in the directory it was created:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code>cp target/tweet-button-plugin-1.0.0-incubating-SNAPSHOT.jar ../../package/target/unomi-1.0.0-incubating-SNAPSHOT/deploy</code></pre>
+</div>
+</div>
+</div>
+<div class="sect4">
+<h5 id="_testing_the_samples">Testing the samples</h5>
+<div class="paragraph">
+<p>You can now go to <a href="http://localhost:8181/index.html">http://localhost:8181/index.html</a> to test the samples code. The page is very simple, you will see a Twitter button, which, once clicked, will open a new window to tweet about the current page. The original page should be updated with the new values of the properties coming from Unomi. Additionnally, the raw JSON response is displayed.</p>
+</div>
+<div class="paragraph">
+<p>We will now explain in greater details some concepts and see how the example works.</p>
+</div>
+</div>
+</div>
+<div class="sect3">
+<h4 id="_interacting_with_the_context_server">4.3.2. Interacting with the context server</h4>
+<div class="paragraph">
+<p>There are essentially two modalities to interact with the context server, reflecting different types of Unomi users: context server clients and context server integrators.</p>
+</div>
+<div class="paragraph">
+<p><strong>Context server clients</strong> are usually web applications or content management systems. They interact with Unomi by providing raw, uninterpreted contextual data in the form of events and associated metadata. That contextual data is then processed by the context server to be fed to clients once actionable. In that sense context server clients are both consumers and producers of contextual data. Context server clients will mostly interact with Unomi using a single entry point called the <code>ContextServlet</code>, requesting context for the current user and providing any triggered events along the way.</p>
+</div>
+<div class="paragraph">
+<p>On the other hand, <strong>context server integrators</strong> provide ways to feed more structured data to the context server either to integrate with third party services or to provide analysis of the uninterpreted data provided by context server clients. Such integration will mostly be done using Unomi&#8217;s API either directly using Unomi plugins or via the provided REST APIs. However, access to REST APIs is restricted due for security reasons, requiring privileged access to the Unomi server, making things a little more complex to set up.</p>
+</div>
+<div class="paragraph">
+<p>For simplicity&#8217;s sake, this document will focus solely on the first use case and will interact only with the context servlet.</p>
+</div>
+</div>
+<div class="sect3">
+<h4 id="_retrieving_context_information_from_unomi_using_the_context_servlet">4.3.3. Retrieving context information from Unomi using the context servlet</h4>
+<div class="paragraph">
+<p>Unomi provides two ways to retrieve context: either as a pure JSON object containing strictly context information or as a couple of JSON objects augmented with javascript functions that can be used to interact with the Unomi server using the <code>&lt;context server base URL&gt;/context.json</code> or <code>&lt;context server base URL&gt;/context.js</code> URLs, respectively.</p>
+</div>
+<div class="paragraph">
+<p>Below is an example of asynchronously loading the initial context using the javascript version, assuming a default Unomi install running on <code><a href="http://localhost:8181" class="bare">http://localhost:8181</a></code>:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code class="language-javascript" data-lang="javascript">// Load context from Unomi asynchronously
+(function (document, elementToCreate, id) {
+    var js, fjs = document.getElementsByTagName(elementToCreate)[0];
+    if (document.getElementById(id)) return;
+    js = document.createElement(elementToCreate);
+    js.id = id;
+    js.src = 'http://localhost:8181/context.js';
+    fjs.parentNode.insertBefore(js, fjs);
+}(document, 'script', 'context'));</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>This initial context results in a javascript file providing some functions to interact with the context server from javascript along with two objects: a <code>cxs</code> object containing
+information about the context for the current user and a <code>digitalData</code> object that is injected into the browser’s <code>window</code> object (leveraging the
+<a href="http://www.w3.org/2013/12/ceddl-201312.pdf">Customer Experience Digital Data Layer</a> standard). Note that this last object is not under control of the context server and clients
+ are free to use it or not. Our example will not make use of it.</p>
+</div>
+<div class="paragraph">
+<p>On the other hand, the <code>cxs</code> top level object contains interesting contextual information about the current user:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code class="language-json" data-lang="json">{
+  "profileId":&lt;identifier of the profile associated with the current user&gt;,
+  "sessionId":&lt;identifier of the current user session&gt;,
+  "profileProperties":&lt;requested profile properties, if any&gt;,
+  "sessionProperties":&lt;requested session properties, if any&gt;,
+  "profileSegments":&lt;segments the profile is part of if requested&gt;,
+  "filteringResults":&lt;result of the evaluation of personalization filters&gt;,
+  "trackedConditions":&lt;tracked conditions in the source page, if any&gt;
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>We will look at the details of the context request and response later.</p>
+</div>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_example">4.4. Example</h3>
+<div class="sect3">
+<h4 id="_html_page">4.4.1. HTML page</h4>
+<div class="paragraph">
+<p>The code for the HTML page with our Tweet button can be found at <a href="https://github.com/apache/incubator-unomi/blob/master/wab/src/main/webapp/index.html">https://github.com/apache/incubator-unomi/blob/master/wab/src/main/webapp/index.html</a>.</p>
+</div>
+<div class="paragraph">
+<p>This HTML page is fairly straightforward: we create a tweet button using the Twitter API while a Javascript script performs the actual logic.</p>
+</div>
+</div>
+<div class="sect3">
+<h4 id="_javascript">4.4.2. Javascript</h4>
+<div class="paragraph">
+<p>Globally, the script loads both the twitter widget and the initial context asynchronously (as shown previously). This is accomplished using fairly standard javascript code and we won&#8217;t look at it here. Using the Twitter API, we react to the <code>tweet</code> event and call the Unomi server to update the user&#8217;s profile with the required information, triggering a custom <code>tweetEvent</code> event. This is accomplished using a <code>contextRequest</code> function which is an extended version of a classic <code>AJAX</code> request:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code class="language-javascript" data-lang="javascript">function contextRequest(successCallback, errorCallback, payload) {
+    var data = JSON.stringify(payload);
+    // if we don't already have a session id, generate one
+    var sessionId = cxs.sessionId || generateUUID();
+    var url = 'http://localhost:8181/context.json?sessionId=' + sessionId;
+    var xhr = new XMLHttpRequest();
+    var isGet = data.length &lt; 100;
+    if (isGet) {
+        xhr.withCredentials = true;
+        xhr.open("GET", url + "&amp;payload=" + encodeURIComponent(data), true);
+    } else if ("withCredentials" in xhr) {
+        xhr.open("POST", url, true);
+        xhr.withCredentials = true;
+    } else if (typeof XDomainRequest != "undefined") {
+        xhr = new XDomainRequest();
+        xhr.open("POST", url);
+    }
+    xhr.onreadystatechange = function () {
+        if (xhr.readyState != 4) {
+            return;
+        }
+        if (xhr.status ==== 200) {
+            var response = xhr.responseText ? JSON.parse(xhr.responseText) : undefined;
+            if (response) {
+                cxs.sessionId = response.sessionId;
+                successCallback(response);
+            }
+        } else {
+            console.log("contextserver: " + xhr.status + " ERROR: " + xhr.statusText);
+            if (errorCallback) {
+                errorCallback(xhr);
+            }
+        }
+    };
+    xhr.setRequestHeader("Content-Type", "text/plain;charset=UTF-8"); // Use text/plain to avoid CORS preflight
+    if (isGet) {
+        xhr.send();
+    } else {
+        xhr.send(data);
+    }
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>There are a couple of things to note here:</p>
+</div>
+<div class="ulist">
+<ul>
+<li>
+<p>If we specify a payload, it is expected to use the JSON format so we <code>stringify</code> it and encode it if passed as a URL parameter in a <code>GET</code> request.</p>
+</li>
+<li>
+<p>We need to make a <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS"><code>CORS</code></a> request since the Unomi server is most likely not running on the same host than the one from which the request originates. The specific details are fairly standard and we will not explain them here.</p>
+</li>
+<li>
+<p>We need to either retrieve (from the initial context we retrieved previously using <code>cxs.sessionId</code>) or generate a session identifier for our request since Unomi currently requires one.</p>
+</li>
+<li>
+<p>We&#8217;re calling the <code>ContextServlet</code> using the default install URI, specifying the session identifier: <code><a href="http://localhost:8181/context.json?sessionId=&#39" class="bare">http://localhost:8181/context.json?sessionId=&#39</a>; + sessionId</code>. This URI requests context from Unomi, resulting in an updated <code>cxs</code> object in the javascript global scope. The context server can reply to this request either by returning a JSON-only object containing solely the context information as is the case when the requested URI is <code>context.json</code>. However, if the client requests <code>context.js</code> then useful functions to interact with Unomi are added to the <code>cxs</code> object in addition to the context information as depicted above.</p>
+</li>
+<li>
+<p>We don&#8217;t need to provide any authentication at all to interact with this part of Unomi since we only have access to read-only data (as well as providing events as we shall see later on). If we had been using the REST API, we would have needed to provide authentication information as well.</p>
+</li>
+</ul>
+</div>
+<div class="sect4">
+<h5 id="_context_request_and_response_structure">Context request and response structure</h5>
+<div class="paragraph">
+<p>The interesting part, though, is the payload. This is where we provide Unomi with contextual information as well as ask for data in return. This allows clients to specify which type of information they are interested in getting from the context server as well as specify incoming events or content filtering or property/segment overrides for personalization or impersonation. This conditions what the context server will return with its response.</p>
+</div>
+<div class="paragraph">
+<p>Let&#8217;s look at the context request structure:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code class="language-json" data-lang="json">{
+    source: &lt;Item source of the context request&gt;,
+    events: &lt;optional array of triggered events&gt;,
+    requiredProfileProperties: &lt;optional array of property identifiers&gt;,
+    requiredSessionProperties: &lt;optional array of property identifiers&gt;,
+    filters: &lt;optional array of filters to evaluate&gt;,
+    profileOverrides: &lt;optional profile containing segments,scores or profile properties to override&gt;,
+            - segments: &lt;optional array of segment identifiers&gt;,
+            - profileProperties: &lt;optional map of property name / value pairs&gt;,
+            - scores: &lt;optional map of score id / value pairs&gt;
+    sessionPropertiesOverrides: &lt;optional map of property name / value pairs&gt;,
+    requireSegments: &lt;boolean, whether to return the associated segments&gt;
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>We will now look at each part in greater details.</p>
+</div>
+<div class="sect5">
+<h6 id="_source">Source</h6>
+<div class="paragraph">
+<p>A context request payload needs to at least specify some information about the source of the request in the form of an <code>Item</code> (meaning identifier, type and scope plus any additional properties we might have to provide), via the <code>source</code> property of the payload. Of course the more information can be provided about the source, the better.</p>
+</div>
+</div>
+<div class="sect5">
+<h6 id="_filters">Filters</h6>
+<div class="paragraph">
+<p>A client wishing to perform content personalization might also specify filtering conditions to be evaluated by the context server so that it can tell the client whether the content associated with the filter should be activated for this profile/session. This is accomplished by providing a list of filter definitions to be evaluated by the context server via the <code>filters</code> field of the payload. If provided, the evaluation results will be provided in the <code>filteringResults</code> field of the resulting <code>cxs</code> object the context server will send.</p>
+</div>
+</div>
+<div class="sect5">
+<h6 id="_overrides">Overrides</h6>
+<div class="paragraph">
+<p>It is also possible for clients wishing to perform user impersonation to specify properties or segments to override the proper ones so as to emulate a specific profile, in which case the overridden value will temporarily replace the proper values so that all rules will be evaluated with these values instead of the proper ones. The <code>segments</code> (array of segment identifiers), <code>profileProperties</code> (maps of property name and associated object value) and <code>scores</code> (maps of score id and value) all wrapped in a profileOverrides object and the <code>sessionPropertiesOverrides</code> (maps of property name and associated object value) fields allow to provide such information. Providing such overrides will, of course, impact content filtering results and segments matching for this specific request.</p>
+</div>
+</div>
+<div class="sect5">
+<h6 id="_controlling_the_content_of_the_response">Controlling the content of the response</h6>
+<div class="paragraph">
+<p>The clients can also specify which information to include in the response by setting the <code>requireSegments</code> property to true if segments the current profile matches should be returned or provide an array of property identifiers for <code>requiredProfileProperties</code> or <code>requiredSessionProperties</code> fields to ask the context server to return the values for the specified profile or session properties, respectively. This information is provided by the <code>profileProperties</code>, <code>sessionProperties</code> and <code>profileSegments</code> fields of the context server response.</p>
+</div>
+<div class="paragraph">
+<p>Additionally, the context server will also returns any tracked conditions associated with the source of the context request. Upon evaluating the incoming request, the context server will determine if there are any rules marked with the <code>trackedCondition</code> tag and which source condition matches the source of the incoming request and return these tracked conditions to the client. The client can use these tracked conditions to learn that the context server can react to events matching the tracked condition and coming from that source. This is, in particular, used to implement form mapping (a solution that allows clients to update user profiles based on values provided when a form is submitted).</p>
+</div>
+</div>
+<div class="sect5">
+<h6 id="_events_2">Events</h6>
+<div class="paragraph">
+<p>Finally, the client can specify any events triggered by the user actions, so that the context server can process them, via the <code>events</code> field of the context request.</p>
+</div>
+</div>
+<div class="sect5">
+<h6 id="_default_response">Default response</h6>
+<div class="paragraph">
+<p>If no payload is specified, the context server will simply return the minimal information deemed necessary for client applications to properly function: profile identifier, session identifier and any tracked conditions that might exist for the source of the request.</p>
+</div>
+</div>
+</div>
+<div class="sect4">
+<h5 id="_context_request_for_our_example">Context request for our example</h5>
+<div class="paragraph">
+<p>Now that we&#8217;ve seen the structure of the request and what we can expect from the context response, let&#8217;s examine the request our component is doing.</p>
+</div>
+<div class="paragraph">
+<p>In our case, our <code>source</code> item looks as follows: we specify a scope for our application (<code>unomi-tweet-button-samples</code>), specify that the item type (i.e. the kind of element that is the source of our event) is a <code>page</code> (which corresponds, as would be expected, to a web page), provide an identifier (in our case, a Base-64 encoded version of the page&#8217;s URL) and finally, specify extra properties (here, simply a <code>url</code> property corresponding to the page&#8217;s URL that will be used when we process our event in our Unomi extension).</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code class="language-javascript" data-lang="javascript">var scope = 'unomi-tweet-button-samples';
+var itemId = btoa(window.location.href);
+var source = {
+    itemType: 'page',
+    scope: scope,
+    itemId: itemId,
+    properties: {
+        url: window.location.href
+    }
+};</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>We also specify that we want the context server to return the values of the <code>tweetNb</code> and <code>tweetedFrom</code> profile properties in its response. Finally, we provide a custom event of type <code>tweetEvent</code> with associated scope and source information, which matches the source of our context request in this case.</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code class="language-javascript" data-lang="javascript">var contextPayload = {
+    source: source,
+    events: [
+        {
+            eventType: 'tweetEvent',
+            scope: scope,
+            source: source
+        }
+    ],
+    requiredProfileProperties: [
+        'tweetNb',
+        'tweetedFrom'
+    ]
+};</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>The <code>tweetEvent</code> event type is not defined by default in Unomi. This is where our Unomi plugin comes into play since we need to tell Unomi how to react when it encounters such events.</p>
+</div>
+</div>
+<div class="sect4">
+<h5 id="_unomi_plugin_overview">Unomi plugin overview</h5>
+<div class="paragraph">
+<p>In order to react to <code>tweetEvent</code> events, we will define a new Unomi rule since this is exactly what Unomi rules are supposed to do. Rules are guarded by conditions and if these
+ conditions match, the associated set of actions will be executed. In our case, we want our new
+ <a href="https://github.com/apache/incubator-unomi/blob/master/samples/tweet-button-plugin/src/main/resources/META-INF/cxs/rules/incrementTweetNumber.json"><code>incrementTweetNumber</code></a> rule to only react to <code>tweetEvent</code> events and
+ we want it to perform the profile update accordingly: create the property types for our custom properties if they don&#8217;t exist and update them. To do so, we will create a
+ custom
+ <a href="https://github.com/apache/incubator-unomi/blob/master/samples/tweet-button-plugin/src/main/resources/META-INF/cxs/actions/incrementTweetNumberAction.json"><code>incrementTweetNumberAction</code></a> action that will be triggered any time our rule matches. An action is some custom code that is deployed in the context server and can access the
+ Unomi API to perform what it is that it needs to do.</p>
+</div>
+</div>
+<div class="sect4">
+<h5 id="_rule_definition">Rule definition</h5>
+<div class="paragraph">
+<p>Let&#8217;s look at how our custom <a href="https://github.com/apache/incubator-unomi/blob/master/samples/tweet-button-plugin/src/main/resources/META-INF/cxs/rules/incrementTweetNumber.json"><code>incrementTweetNumber</code></a> rule is defined:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code class="language-json" data-lang="json">{
+  "metadata": {
+    "id": "smp:incrementTweetNumber",
+    "name": "Increment tweet number",
+    "description": "Increments the number of times a user has tweeted after they click on a tweet button"
+  },
+  "raiseEventOnlyOnceForSession": false,
+  "condition": {
+    "type": "eventTypeCondition",
+    "parameterValues": {
+      "eventTypeId": "tweetEvent"
+    }
+  },
+  "actions": [
+    {
+      "type": "incrementTweetNumberAction",
+      "parameterValues": {}
+    }
+  ]
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>Rules define a metadata section where we specify the rule name, identifier and description.</p>
+</div>
+<div class="paragraph">
+<p>When rules trigger, a specific event is raised so that other parts of Unomi can react to it accordingly. We can control how that event should be raised. Here we specify that the event should be raised each time the rule triggers and not only once per session by setting <code>raiseEventOnlyOnceForSession</code> to <code>false</code>, which is not strictly required since that is the default. A similar setting (<code>raiseEventOnlyOnceForProfile</code>) can be used to specify that the event should only be raised once per profile if needed.</p>
+</div>
+<div class="paragraph">
+<p>We could also specify a priority for our rule in case it needs to be executed before other ones when similar conditions match. This is accomplished using the <code>priority</code> property. We&#8217;re using the default priority here since we don&#8217;t have other rules triggering on `tweetEvent`s and don&#8217;t need any special ordering.</p>
+</div>
+<div class="paragraph">
+<p>We then tell Unomi which condition should trigger the rule via the <code>condition</code> property. Here, we specify that we want our rule to trigger on an <code>eventTypeCondition</code> condition. Unomi can be extended by adding new condition types that can enrich how matching or querying is performed. The condition type definition file specifies which parameters are expected for our condition to be complete. In our case, we use the built-in event type condition that will match if Unomi receives an event of the type specified in the condition&#8217;s <code>eventTypeId</code> parameter value: <code>tweetEvent</code> here.</p>
+</div>
+<div class="paragraph">
+<p>Finally, we specify a list of actions that should be performed as consequences of the rule matching. We only need one action of type <code>incrementTweetNumberAction</code> that doesn&#8217;t require any parameters.</p>
+</div>
+</div>
+<div class="sect4">
+<h5 id="_action_definition">Action definition</h5>
+<div class="paragraph">
+<p>Let&#8217;s now look at our custom <a href="https://github.com/apache/incubator-unomi/blob/master/samples/tweet-button-plugin/src/main/resources/META-INF/cxs/actions/incrementTweetNumberAction.json"><code>incrementTweetNumberAction</code></a> action type definition:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code class="language-json" data-lang="json">{
+  "id": "incrementTweetNumberAction",
+  "actionExecutor": "incrementTweetNumber",
+  "systemTags": [
+    "event"
+  ],
+  "parameters": []
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>We specify the identifier for the action type, a list of systemTags if needed: here we say that our action is a consequence of events using the <code>event</code> tag. Our actions does not require any parameters so we don&#8217;t define any.</p>
+</div>
+<div class="paragraph">
+<p>Finally, we provide a mysterious <code>actionExecutor</code> identifier: <code>incrementTweetNumber</code>.</p>
+</div>
+</div>
+<div class="sect4">
+<h5 id="_action_executor_definition">Action executor definition</h5>
+<div class="paragraph">
+<p>The action executor references the actual implementation of the action as defined in our <a href="https://github.com/apache/incubator-unomi/blob/master/samples/tweet-button-plugin/src/main/resources/OSGI-INF/blueprint/blueprint.xml">blueprint definition</a>:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;blueprint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"&gt;
+
+    &lt;reference id="profileService" interface="org.apache.unomi.api.services.ProfileService"/&gt;
+
+    &lt;!-- Action executor --&gt;
+    &lt;service id="incrementTweetNumberAction" interface="org.apache.unomi.api.actions.ActionExecutor"&gt;
+        &lt;service-properties&gt;
+            &lt;entry key="actionExecutorId" value="incrementTweetNumber"/&gt;
+        &lt;/service-properties&gt;
+        &lt;bean class="org.apache.unomi.examples.unomi_tweet_button_plugin.actions.IncrementTweetNumberAction"&gt;
+            &lt;property name="profileService" ref="profileService"/&gt;
+        &lt;/bean&gt;
+    &lt;/service&gt;
+&lt;/blueprint&gt;</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>In standard Blueprint fashion, we specify that we will need the <code>profileService</code> defined by Unomi and then define a service of our own to be exported for Unomi to use. Our service specifies one property: <code>actionExecutorId</code> which matches the identifier we specified in our action definition. We then inject the profile service in our executor and we&#8217;re done for the configuration side of things!</p>
+</div>
+</div>
+<div class="sect4">
+<h5 id="_action_executor_implementation">Action executor implementation</h5>
+<div class="paragraph">
+<p>Our action executor definition specifies that the bean providing the service is implemented in the <a href="https://github.com/apache/incubator-unomi/blob/master/samples/tweet-button-plugin/src/main/java/org/apache/unomi/samples/tweet_button_plugin/actions/IncrementTweetNumberAction.java"><code>org.apache.unomi.samples.tweet_button_plugin.actions
+.IncrementTweetNumberAction</code></a> class. This class implements the Unomi <code>ActionExecutor</code> interface which provides a single <code>int execute(Action action, Event event)</code> method: the executor gets the action instance to execute along with the event that triggered it, performs its work and returns an integer status corresponding to what happened as defined by public constants of the <code>EventService</code> interface of Unomi: <code>NO_CHANGE</code>, <code>SESSION_UPDATED</code> or <code>PROFILE_UPDATED</code>.</p>
+</div>
+<div class="paragraph">
+<p>Let&#8217;s now look at the implementation of the method:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code class="language-java" data-lang="java">final Profile profile = event.getProfile();
+Integer tweetNb = (Integer) profile.getProperty(TWEET_NB_PROPERTY);
+List&lt;String&gt; tweetedFrom = (List&lt;String&gt;) profile.getProperty(TWEETED_FROM_PROPERTY);
+
+if (tweetNb ==== null || tweetedFrom ==== null) {
+    // create tweet number property type
+    PropertyType propertyType = new PropertyType(new Metadata(event.getScope(), TWEET_NB_PROPERTY, TWEET_NB_PROPERTY, "Number of times a user tweeted"));
+    propertyType.setValueTypeId("integer");
+    service.createPropertyType(propertyType);
+
+    // create tweeted from property type
+    propertyType = new PropertyType(new Metadata(event.getScope(), TWEETED_FROM_PROPERTY, TWEETED_FROM_PROPERTY, "The list of pages a user tweeted from"));
+    propertyType.setValueTypeId("string");
+    propertyType.setMultivalued(true);
+    service.createPropertyType(propertyType);
+
+    tweetNb = 0;
+    tweetedFrom = new ArrayList&lt;&gt;();
+}
+
+profile.setProperty(TWEET_NB_PROPERTY, tweetNb + 1);
+final String sourceURL = extractSourceURL(event);
+if (sourceURL != null) {
+    tweetedFrom.add(sourceURL);
+}
+profile.setProperty(TWEETED_FROM_PROPERTY, tweetedFrom);
+
+return EventService.PROFILE_UPDATED;</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>It is fairly straightforward: we retrieve the profile associated with the event that triggered the rule and check whether it already has the properties we are interested in. If not, we create the associated property types and initialize the property values.</p>
+</div>
+<div class="quoteblock">
+<blockquote>
+<div class="paragraph">
+<p>Note that it is not an issue to attempt to create the same property type multiple times as Unomi will not add a new property type if an identical type already exists.</p>
+</div>
+</blockquote>
+</div>
+<div class="paragraph">
+<p>Once this is done, we update our profile with the new property values based on the previous values and the metadata extracted from the event using the <code>extractSourceURL</code> method which uses our <code>url</code> property that we&#8217;ve specified for our event source. We then return that the profile was updated as a result of our action and Unomi will properly save it for us when appropriate. That&#8217;s it!</p>
+</div>
+<div class="paragraph">
+<p>For reference, here&#8217;s the <code>extractSourceURL</code> method implementation:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="highlight"><code class="language-java" data-lang="java">private String extractSourceURL(Event event) {
+    final Item sourceAsItem = event.getSource();
+    if (sourceAsItem instanceof CustomItem) {
+        CustomItem source = (CustomItem) sourceAsItem;
+        final String url = (String) source.getProperties().get("url");
+        if (url != null) {
+            return url;
+        }
+    }
+
+    return null;
+}</code></pre>
+</div>
+</div>
+</div>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_conclusion">4.5. Conclusion</h3>
+<div class="paragraph">
+<p>We have seen a simple example how to interact with Unomi using a combination of client-side code and Unomi plugin. Hopefully, this provided an introduction to the power of what Unomi can do and how it can be extended to suit your needs.</p>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_annex">4.6. Annex</h3>
+<div class="paragraph">
+<p>Here is an overview of how Unomi processes incoming requests to the <code>ContextServlet</code>.
+image: images/unomi-request.png[Unomi request overview]</p>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_weather_update_samples">4.7. Weather update samples</h3>
+
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_connectors">5. Connectors</h2>
+<div class="sectionbody">
+<div class="sect2">
+<h3 id="_connectors_2">5.1. Connectors</h3>
+<div class="paragraph">
+<p>Apache Unomi provides the following connectors:</p>
+</div>
+<div class="ulist">
+<ul>
+<li>
+<p><a href="salesforce-connectors.html">Salesforce CRM connectors</a></p>
+</li>
+</ul>
+</div>
+<div class="sect3">
+<h4 id="_call_for_contributors">5.1.1. Call for contributors</h4>
+<div class="paragraph">
+<p>We are looking for help with the development of additional connectors. Any contribution (large or small) is more than welcome. Feel free to discuss this in our <a href="../../mail-lists.html">mailing list</a>.</p>
+</div>
+</div>
+</div>
+<div class="sect2">
+<h3 id="_apache_unomi_salesforce_connector">5.2. Apache Unomi Salesforce Connector</h3>
+<div class="paragraph">
+<p>This connectors makes it possible to push and pull data to/from the Salesforce CRM. It can copy information between
+Apache Unomi profiles and Salesforce Leads.</p>
+</div>
+<div class="sect3">
+<h4 id="_getting_started_2">5.2.1. Getting started</h4>
+<div class="paragraph">
+<p>.</p>
+</div>
+<div class="paragraph">
+<p>Create a new developer account here:</p>
+</div>
+<div class="listingblock">
+<div class="content">

[... 1546 lines stripped ...]