ComponentOne Web API Edition
Services / Visitor API / Getting Started with Visitor API
In This Topic
    Getting Started with Visitor API
    In This Topic

    This getting started section guides you through a process of creating a Web API application to get the visitor data using the Vissitor API.

    Add Visitor API to Server API

    1. Create a new Web API Core application.
    2. Add the C1.AspNetCore.Api.Visitor NuGet package to the application.

    Configure the API

    You can choose to configure the API either using IP2Location Database or GoogleMap API. To configure the api using the IP2Location Database, see Configuring IP2Location Database. If you want to configure the API using the GoogleMap API, see Configuring Google Map API.

    Note that you can set the following in ConfigureServices method of startup.cs file, if you do not want to use any location provider. This will allow you to use all other visitor information.

    Copy Code
    services.ConfigureVisitor(builder =>

    Include JS Client Script to Client Project

    For synchronous loading of visitor data, use the following code.

    Copy Code
    <script src="{host}/api/visitor/visitor-client.min.js"></script>

    For asynchronous loading of visitor data, use the following code.

    Copy Code
       function onVisitorLoaded(visitorData) {
            Console.log visitorData
    <script async defer src="{host}/api/visitor/visitor-client.min.js?callback=onVisitorLoaded"></script>

    Access Visitor Information

    To get the complete visitor data, use the following code:

    var visitorData= window.visitor.getData();

    To get the country code of the visitor, use the following code:

    window.visitor.getDataAsync(function (visitorData){
           // visitorData.geo.countryCode

    For detailed list of the visitor data fetched on the client-side, see Visitor Data Information.