API Usage Patterns - medullan/navocat-collector GitHub Wiki
The diagram below depicts the recommended use case for the collector APIs, for both the GIF and JSON endpoints. Refer to the API Documentation for specifics on expected parameters. Throughout this document, hits will be used as a general term for calling either the page or track endpoints depicted below.
##API Summary
API | Endpoints | Description |
---|---|---|
IDENTIFY | POST /identify.json GET /identify.gif | Stores identifying info for any user, and returns an analytics profile id for that user, which is used in all subsequent calls. |
PROFILE | POST /profile.json GET /profile.gif |
Stores profile info for any user, which is added to that user’s subsequent analytics events. |
PAGE | POST /page.json GET /page.gif |
Records a web page view, persists the hit to disk and google analytics. |
TRACK | POST /track.json GET /track.gif |
Records a user interaction of any other type, persists the hit to disk and google analytics. |
Fig 1.0 and 2.0 represents a typical flow for creating users' analytics profile to send hit information to the appropriate locations, refer to Fig 3.0 for more information. Once the analytics profile is created, the profile id should be used on all subsequent request to aggregate hit information for any given user.
Anonymous users in terms of the Collector are users without a profile id attached to their hit requests. Each request without a profile id will appear as a hit from a different user.
Usually, when setting up a client to use the Collector, the client only needs to call the identify endpoint once, and thereafter call the relevant hit APIs (page or track). In practice, identify should be used on user authentication, profile to update their demographic information, page for page loads, and track for page events e.g. button click.
A POST request in JSON format can be sent to the JSON version of the APIs, this version of the API is intended for server-side code or mobile apps. The request parameters can be encoded in the query string or included in the post body.
A GET request can be made to the GIF version of the APIs. This method is preferred for client-side code, as there are no cross-domain permission issues. The response in the case of the GIF route will be a 1x1 clear pixel GIF image, and the response may also contain a first-party cookie with the user's analytics profile id.
Fig 3.0 Illustrates a very high-level view of the Navocat Collector data flow. Following from Fig 1.0 and Fig 2.0 once anyone of these flows are completed, the Collector will send the relevant analytics information to the analytics platform and write the necessary analytics information to disk. One thing to note, in practice these tasks are done in parallel for performance gains.