paronne edited this page Dec 18, 2014 · 16 revisions


The svyGoogleAnalytics module offer an API for Google Analytics tracking.

Use svyGoogleAnalytics to analyze your customer behavior on your Servoy solution and help you in understanding how to better meet the needs of your customer. Use the API to track the user behavior and analyze the results in your Google Analytics report dashboard accessible on the Web.

The Servoy GoogleAnlytics API are implemented on top of the Google Analytics API. The API allows you to track pages visiting and events of the User Agent.

Page Tracking

Use Page tracking to get a Flow Visualization reports and let you see and analyze the path a visitor takes on your site. See where they came from, the pages they moved through, and where they exited your site. Flow Visualization help you track the routes people take to reach you, and the devices they use to get there, so you can meet them where they are and improve the visitor experience.

Event Tracking

How do visitors actually interact with your pages? Use Event Tracking to measure activities like clicks, downloads, uploads.

Event tracking within a Servoy solution might be generated from you on meaningful clicks or meaningful events. Depending on what you would like to analyze is up to you define how to describe events.

Using the API

Before using the svyGoogleAnalytics API you must register a Google Analytics account and obtain a GA-Tracking code for your domain.

Init GoogleAnalytics session

The svyGoogleAnalytics runs a Servoy Headless client to handle tracking requests. As first thing you should set the GoogleAnalytics Remote Dispatch User to start corretly Headless client. Use any Servoy User as Remote Dispatch User.

try {   
        // set the remote dispatch user and start the GA Headless client
	scopes.svyGoogleAnalytics.setRemoteDispatchUser(servoyUserName, password)
} catch (e) {
	// the headless client is already started.

Note the remoteDispatchUser should be set only once. The API call will trigger an exception if the GA Headless client is already running.

Register your GA Tracking code and init the session, or resume the session if found. Use different GA Tracking code to analyze different Servoy solutions.

// init the GA Session
if (!scopes.svyGoogleAnalytics.initSession(GA_TRACKING_CODE)) {
	throw new scopes.svyExceptions.IllegalStateException('GA cannot init session !')

Is not possible to create multiple GASession within the same Servoy solution.

Track Pages and Events

The API does not constrains the Page and Event definition. Depending on your needs is up to you define what a page is; you might want to analyze any Servoy form or just meaningful forms as Menu and specific Layouts. In the first case you might want to set the full context path, from the main window form until the shown form, as tracked page allowing you to distinguish from which tab panel the form has been visited.

Use the session to trackPageView, trackEvent.

var session = scopes.svyGoogleAnalytics.getClientSession();
session.trackPageView(controller.getName(), application.getSolutionName() + '/' +controller.getName());
session.trackEvent(controller.getName(), application.getSolutionName() + '/' +controller.getName(), null, 'click', 'button-click', 'label', 'value');

Execute custom GA requests

Create a GARequest from the GA session Object to execute custom GA requests. Set the requestType of the custom request to PAGE_VIEW or EVENT

requestType The request type. Use null for page view (e.g GA_REQUEST_TYPES.EVENT for event type)

pageTitle The page title for tracking page views. Ideally use formName

pageRequest The requested URL. ideally show solutionName concatenated to the formName or form full form context (e.g application.getSolutionName() + '/' + controller.formName)

pageReferring The referring URL

eventCategory The category assigned to an event (e.g., Report or Downloads)

eventAction The action assigned to an event (e.g., View file, Download file)

eventLabel The label assigned to an event (any descriptive string you choose)

eventValue Value used for event requests (any value you choose)

adSenseID Unique ID generated for integration with ad-sense

var req = session.createRequest();
req.requestType = scopes.svyGoogleAnalytics.GA_REQUEST_TYPES.PAGE_VIEW;
req.pageTitle = controller.getName();
req.pageRequest = application.getSolutionName() + '/' +controller.getName();
req.eventAction = 'onShow'
       if (statusCode == plugins.http.HTTP_STATUS.SC_OK) {
               // request success
       } else {
               // tracking request failed.

Analyze the user behavior

Access with your Google Analytics account at the GA web site to access your dashboard and reports. Go to the reporting section of the domain you would like to analyze.

Real Time Data

Data are generally published on Google Analytics one day after. Open the Real Time Overview to analyze real time data and see how many people are using your solution right now, where they came from, and what they're viewing.


Open the Behavior section to analyze the tracked pages and events. The Overview section provides a summary of page views and access frequency.

Behavior Flow reports let you see and analyze the path a user takes on your solution. See where they came from, the pages they moved through, and where they exited your solution.

Events reports let you see and analyze the actions a user takes on your solution. See on what they click in which page what from where they download your content. See the User Events Flow to analyze how he behaves on your page.

Depending on how your page is presented the User might behave differently; analyze the same events generated from same meaningful pages but differently presented to analyze on which layout the user generates more meaningful actions, as Purchase, Download. Analyze the event detail in the Top Events sub-section and set Page as Secondary Dimension

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.