Google Analytics Package

Morfik’s Google Analytics package provides the required functionality to enable use of Google Analytics features in web applications created with Morfik. Please watch this introduction video to learn about the capabilities of the Google Analytics Package.


package-view.png
[ No Live Demo]
package-down.png


Quick Walkthrough

Before you get started you will have to create a Google Analytics account if you don’t have one already. Once you have registered, you will need to locate the tracking code assigned to your account by Google, as shown below (Figure 1 Locating the tracking code assigned to you by Google).


locate-tracking-code-assigned-by-google-fig1.png
Figure 1: Locating the tracking code assigned to you by Google


Now you can use the “Used Packages” command on the project ribbon to add the package to your project (Figure 2 Used Packages Command), or simply drag the package file onto the application main client area.


security-fig1.png
Figure 2: Used Packages Command


Switch to Project View, select Events panel and assign OnStart event. This is where you need to enter the tracking code:

FX Code

Procedure Project4XApp.XAppStart(Sender: TObject); 
Begin 
      GA_AccountNumber := 'UA-12345678-9'; 
End;


You will also have to add mfk_GoogleAnalytics to the uses section of your module as follows:

FX Code

Implementation 
Uses 
    mfk_GoogleAnalytics;

Now you are ready to start using Google Analytics.

Tracking Individual Pages

If you need to track individual pages, this is how it can be done: Activate Project View and select View | Browser Code on the ribbon to switch to the browser-side code of your application. Redefine an OpenPage method like this:

FX Code

    Unit Project1XApp; 
 
    Interface 
 
    Type 
    Project1XApp = Class(TXApp) 
      Procedure     OpenPage(PageURL :String; OverrideParams : String);  Override; 
      Published 
         { Events } 
      Private 
         { Private declarations } 
      Public 
         { Public declarations } 
    End; 
 
    Implementation 
 
    Uses mfk_GoogleAnalytics; 
 
    Procedure Project1XApp.OpenPage(PageURL :String; OverrideParams :String);  Override; 
    Begin 
        TrackPageview(PageURL); 
        Inherited OpenPage(PageURL, OverrideParams); 
    End; 
 
    End.

Deploy your application. All visits to your website are now being monitored by Google Analytics!

Note: Data from Google Analytics service is updated every 24 hours at 00:00 on the time zone set in your profile, so results may not necessarily be current.

Using Google Analytics API

Morfik Google Analytics package makes it possible to use all the features provided by Google Analytics. They are exposed through the GooglePageTracker global object (Figure 3 Using Google Analytics API). Please note, you have to add mfk_GoogleAnalytics to the Uses section of your module if you are using GooglePageTracker.

using-google-analytics-api-fig3.png
Figure 3: Using Google Analytics API


Note: You can find a comprehensive description of Google Analytics API at the Google Analytics Developer Docs website.

See Also

Back to top