Google Analytics and Webmaster Tools

Track events with Google Analytics

Outlast Framework has a built-in mechanism to track page interactions, js errors, ajax requests via the ofw.track javascript interface.

By default ofw.track tracks events to Google Analytics. It’s API is very similar to GA’s own:

Of course, you’ll need to have a Google Analytics code included in order for GA tracking to work.

Use data attributes

You can also use the tracking data attributes to track click events on links and objects. Data attributes should be used whereever you’d need to add an onclick attribute.

Non-interaction events

Events that run without user interaction (such as tracking the display of something on the page) need to be called with nonInteraction: true. This will ensure that the event does not influence the bounce rate.

  ofw.track('Legal', 'show', 'Cookie Policy', { nonInteraction: true });

Since these events may run immediately on page load, be careful to place it in ofw.ready() to ensure that all the necessary scripts are ready before the event is actually sent.

Track events in local database

In addition to tracking events in GA, the same interface also tracks events to the local UserEvent model. This is not enabled by default but all you need to do is set the proper zajconf setting in site/index.php settings file:

$zajconf['trackevents_local'] = true;  // If set to true, events will also be recorded in the local UserEvent table. Defaults to false.
$zajconf['trackevents_analytics'] = true;   // If set to true, events will also be recorded in Google Analytics. Defaults to true.

Use HTML files for Google site verification

Google’s Webmaster Tools service (and other services as well) require you to verify domain ownership by uploading an HTML file to the server. Of course, you can always use the meta tag method instead, but the default HTML file upload verification will work like this.

Add the HTML file to the root folder of your project. It’ll be something like google2712d24c4c1we0b9.html. Next, add a rule to the .htaccess file so you enable direct access to this specific file. You should place this rule right above or below where the robots.txt file is defined. Here’s an example:

# explicitly enable robots.txt, favicon.ico
	RewriteRule ^(robots.txt|favicon.ico) site/$1 [L]
# enable Google site verification html
	RewriteRule ^(google2712d24c4c1we0b9.html) $1 [L]

# explicitly enable data folder, but disable private folder by redirecting to error
	RewriteRule ^(data/private)(/)?(.+) site/index.php?error=private [L]

Of course, you’ll need to change the file’s name to whatever the actual file is that you download from Google.

Outlast Web & Mobile Development (c) 2023 | Privacy Policy |