events integration

Event collector (JavaScript)

The event collector collects data from visitor and store it in cookie. The following line include the event collector in your website

<script src="//insights.feedcheck.co/insights.js"></script>

Event forwarder (PHP)

The Event forwarder reads the cookie writen by event collector, enrich it with other information and send it to visitor-insights server

// Visitor insights code
$url = 'https://insights.feedcheck.co/add-event';
$cookieName = 'insights_profile';
$profile = json_decode(stripslashes($_COOKIE[$cookieName]), true);
$profile['name'] = 'contact';
$profile['email'] = $_REQUEST['email'];
$profile['ip'] = $_SERVER['REMOTE_ADDR'];
$profile['cookie_id'] = $profile['id'];

$params = http_build_query($profile);
$ch = curl_init($url.'?'.$params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_exec($ch);
curl_close($ch);

Event forwarder (Python 3, Flask)

The Event forwarder reads the cookie writen by event collector, enrich it with other information and send it to visitor-insights server

import requests, urllib, json, traceback

# send data to insights
def sendEvent(name='', email='', company='', profile='', ipAddress=''):
    try:
        if profile:
            params = json.loads(profile)
            params['name'] = name
            params['cookie_id'] = params['id']

            if 'email' not in params or not params['email']:
                params['email'] = email

            if 'company' not in params or params['company']:
                params['company'] = company

            if ipAddress:
                params['ip'] = ipAddress

            url = "https://insights.feedcheck.co/add-event?" + urllib.parse.urlencode(params, safe='/:,.')
            r = requests.get(url)
    except Exception as e:
        traceback.print_tb(e.__traceback__)

visitorinsights.sendEvent(name='demo' + customer.username,
                                  email=email,
                                  company=company,
                                  profile=request.cookies.get("insights_profile"),
                                  ipAddress=request.remote_addr)