Skip to content

Commit

Permalink
[Behavioral Analytics] Add geo ip and user agent to events (#95433)
Browse files Browse the repository at this point in the history
  • Loading branch information
afoucret committed Apr 25, 2023
1 parent 29421f8 commit 2c5da51
Show file tree
Hide file tree
Showing 17 changed files with 655 additions and 124 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/95433.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 95433
summary: "[Behavioral Analytics] Add geo ip and user agent to events"
area: Application
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@
}
]
},
"body":{
"description":"The event definition",
"required":true
"params": {
"debug": {
"type": "boolean",
"description": "If true, returns event information that will be stored"
}
},
"body": {
"description": "The event definition",
"required": true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,42 @@
}
}
}
},
{
"user_agent": {
"field": "session.user_agent",
"target_field": "session.user_agent",
"ignore_missing": true,
"properties": ["name", "version", "os", "device"],
"extract_device_type": true
}
},
{
"rename": {
"field": "session.user_agent.name",
"target_field": "session.user_agent.browser.name",
"ignore_missing": true
}
},
{
"rename": {
"field": "session.user_agent.version",
"target_field": "session.user_agent.browser.version",
"ignore_missing": true
}
},
{
"geoip": {
"field": "session.ip",
"target_field": "session.location",
"ignore_missing": true
}
},
{
"remove": {
"field": "session.ip",
"ignore_missing": true
}
}
],
"_meta": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,81 @@
"id": {
"ignore_above": 1024,
"type": "keyword"
},
"location": {
"properties": {
"continent_name": {
"ignore_above": 1024,
"type": "keyword"
},
"region_iso_code": {
"ignore_above": 1024,
"type": "keyword"
},
"city_name": {
"ignore_above": 1024,
"type": "keyword"
},
"country_iso_code": {
"ignore_above": 1024,
"type": "keyword"
},
"country_name": {
"ignore_above": 1024,
"type": "keyword"
},
"region_name": {
"ignore_above": 1024,
"type": "keyword"
},
"location": {
"type": "geo_point"
}
}
},
"user_agent": {
"properties": {
"os": {
"properties": {
"name": {
"ignore_above": 1024,
"type": "keyword"
},
"version": {
"ignore_above": 1024,
"type": "keyword"
},
"full": {
"ignore_above": 1024,
"type": "keyword"
}
}
},
"browser": {
"properties": {
"name": {
"ignore_above": 1024,
"type": "keyword"
},
"version": {
"ignore_above": 1024,
"type": "keyword"
}
}
},
"device": {
"properties": {
"name": {
"ignore_above": 1024,
"type": "keyword"
},
"type": {
"ignore_above": 1024,
"type": "keyword"
}
}
}
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,48 @@ teardown:
url: "https://www.elastic.co"
referrer: "http://anotherdomain.com/homepage"

---
"Post page_view analytics event - debug and session information":
- skip:
features: headers

- do:
headers:
X-Forwarded-For: 192.23.12.12
User-Agent: Mozilla/5.0
search_application.post_behavioral_analytics_event:
collection_name: my-test-analytics-collection
event_type: "page_view"
debug: true
body:
session:
id: "123"
user:
id: "456"
page:
url: "https://www.elastic.co"
title: "Elastic - Homepage"
referrer: "http://anotherdomain.com/homepage"
document:
id: "doc-1"
index: "search-index"

- match: { accepted: true }
- match: { event.event.action: "page_view" }
- match: { event.data_stream.type: "behavioral_analytics" }
- match: { event.data_stream.dataset: "events" }
- match: { event.data_stream.namespace: "my-test-analytics-collection" }
- match: { event.session.id: "123" }
- match: { event.session.user_agent: "Mozilla/5.0" }
- match: { event.session.ip: "192.23.12.12" }
- match: { event.document.id: "doc-1" }
- match: { event.document.index: "search-index" }
- match: { event.page.url: "https://www.elastic.co" }
- match: { event.page.title: "Elastic - Homepage" }
- match: { event.page.referrer: "http://anotherdomain.com/homepage" }
- match: { event.user.id: "456" }
- gte: { event.@timestamp: 0 }

# Search event tests ############################################
---
"Post search analytics event":
Expand Down Expand Up @@ -225,9 +267,76 @@ teardown:
query: "test-query"
filters:
brand: "elastic"
products: ["elasticsearch", "kibana"]
products: [ "elasticsearch", "kibana" ]
rating: "[3-5]"

---
"Post search analytics event - debug and session information":
- skip:
features: headers

- do:
headers:
X-Forwarded-For: 192.23.12.12
User-Agent: Mozilla/5.0
search_application.post_behavioral_analytics_event:
collection_name: my-test-analytics-collection
event_type: "search"
debug: true
body:
session:
id: "123"
user:
id: "456"
search:
query: "test-query"
search_application: "my-search-application"
sort:
name: "price"
direction: "desc"
filters:
brand: "elastic"
products: [ "elasticsearch", "kibana" ]
rating: "[3-5]"
page:
current: 1
size: 10
results:
total_results: 150
items:
- document:
id: doc-1
- document:
id: doc-2
index: my-search-index
- page:
url: "https://www.elastic.co"
- page:
url: "https://www.elastic.co/doc/getting-stared"
document:
id: "getting-started"
index: elastic-documentation-en

- match: { accepted: true }
- match: { event.event.action: "search" }
- match: { event.data_stream.type: "behavioral_analytics" }
- match: { event.data_stream.dataset: "events" }
- match: { event.data_stream.namespace: "my-test-analytics-collection" }
- match: { event.session.id: "123" }
- match: { event.session.user_agent: "Mozilla/5.0" }
- match: { event.session.ip: "192.23.12.12" }
- match: { event.search.query: "test-query" }
- match: { event.search.search_application: "my-search-application" }
- match: { event.search.sort.name: "price" }
- match: { event.search.sort.direction: "desc" }
- match: { event.search.filters.brand: [ "elastic" ] }
- match: { event.search.filters.products: [ "elasticsearch", "kibana" ] }
- match: { event.search.filters.rating: [ "[3-5]" ] }
- match: { event.search.page.current: 1 }
- match: { event.search.page.size: 10 }
- match: { event.search.results.total_results: 150 }
- gte: { event.@timestamp: 0 }

# Search click event tests #######################################
---
"Post search_click analytics event":
Expand All @@ -247,6 +356,45 @@ teardown:
search:
query: "test-query"

---
"Post search_click analytics event - debug and session information":
- skip:
features: headers

- do:
headers:
X-Forwarded-For: 192.23.12.12
User-Agent: Mozilla/5.0
search_application.post_behavioral_analytics_event:
collection_name: my-test-analytics-collection
event_type: "search_click"
debug: true
body:
session:
id: "123"
user:
id: "456"
document:
id: "doc-1"
page:
url: "https://www.elastic.co"
search:
query: "test-query"

- match: { accepted: true }
- match: { event.event.action: "search_click" }
- match: { event.data_stream.type: "behavioral_analytics" }
- match: { event.data_stream.dataset: "events" }
- match: { event.data_stream.namespace: "my-test-analytics-collection" }
- match: { event.session.id: "123" }
- match: { event.session.user_agent: "Mozilla/5.0" }
- match: { event.session.ip: "192.23.12.12" }
- match: { event.document.id: "doc-1" }
- match: { event.page.url: "https://www.elastic.co" }
- match: { event.user.id: "456" }
- match: { event.search.query: "test-query" }
- gte: { event.@timestamp: 0 }

---
"Post search_click analytics event - Page Only":
- do:
Expand Down

0 comments on commit 2c5da51

Please sign in to comment.