Skip to content

Visit

Visit

from visit_generator.visitor import Visit

init(visitor, referrer, pattern_id, views, first_visit, last_visit, token=None)

When initialized the Visit class must have a parent Visitor, a referrer string, pattern_id and both first_visit and last_visit set.

pattern_id should come from the pre configured [Pattern][../../utils#pattern]

referrer can be anything but should look like a real piece of data.

It's usually easier to just use Visitor.create_visit().

create_label(label_config, created=None):

Create a Label for this visit. label_config is required and should use LabelConfig from utils, along with ClientLabel. Example:

from visit_generator.utils import LabelConfig, ClientLabel

new_label = LabelConfig('blog type', 'fashion', ClientLabel.TYPE_STRING)
v = Visitor()
v.create_visit().create_label(new_label)

create_page(page_url, created=None):

Create a Page for this visit. page_url is required and can be any string. Recommended to use ClientPage from utils.

create_pages(journey):

Similar to create_page, but accepts an array of arrays to be treated as a journey.

A journey item must contain 3 items: [page_url, datetime, [events]].

An event is a simple array again of just [event_name, revenue]

Example

visit.create_pages([
    ['client.com/', '2021-01-01 09:25:00', []],
    ['client.com/product-view', '2021-01-01 09:30:00', ['Product View', 0]],
    ['client.com/product-view', '2021-01-01 09:31:00', ['Add To Basket', 0]]
]).insert(conn)

create_prediction(prediction, product):

This will give the current Visit a prediction per product. Predictions are between 0 and 1.0. We recommend you use Product

Example

v = Visitor(VisitDefaults.FIRST_VISIT.value, VisitDefaults.LAST_VISIT.value, account=account)

v.create_visit('www.google.com', Pattern.SEO.value, 4, duration=30)\
    .create_page(ClientPage.HOME.value).visit\
    .create_prediction(prediction=0.2, product=Product.GENERIC)\
    .insert(conn)

create_visit_detail(user_agent=None, location_details=None, ip="127.0.0.1", language="en-US,en;q=0.9", timezone_offset=0, browser_family=None, os_family=None, city_name=None, country_name=None, continent_name=None, latitude=None, longitude=None, country_iso_code=None):

Create a VisitDetail for this visit. It is recommend to only use user_agent and location rather than passing in each individual param. Though the option exists if needed.

For the user_agent param please see UserAgents and for location_details utilise the generators found in VisitDetailGen

VisitDetail

from visit_generator.visitor import VisitDetail

Base class that holds Visit Details as seen in the generators function in VisitDetailGen