GTM Template


This documentation shows how you can use the Countly GTM SDK in Google Tag Manager platform.

You can reach the source code of the SDK from its Git repo here.

Adding the SDK to the Project

You can reach the Countly SDK template in your Google Tag Manager container through:

Workspace > Tags > New > Tag Configuration > Community Template Gallery > Countly Analytics

Another method to get the SDK template is to add it manually after downloading it from the Git repo here. You can either download it as a zip file and extract its content:

Code > Download ZIP 

or you can clone the repo and reach files directly:

git clone

After you should import the template.tpl file you have downloaded to your container through:

Workspace > Templates > New > Import

Now it should be available at:

Workspace > Tags > New > Tag Configuration > Countly Analytics

SDK Integration

Minimal Setup

The first thing you should be doing with the SDK template is to initialize the SDK as soon as possible on your web page by selecting a proper trigger. Initialization trigger is a good candidate for this. For SDK initialization the template offers the action Initialize the SDK in the drop down menu:

Here the Server URL and the App Key are mandatory values. Please check here for more information on how to acquire your application key (APP_KEY) and server URL.

Enabling Features

After setting up you App Key and Server URL you will see checkboxes below. These are optional features of the SDK that you can enable during initialization:

  • Enable SDK Logs: Enables the SDK to print logs in browser console for debugging 
  • Track Sessions: Enables automatic session tracking
  • Track Page Views: Enables automatic view tracking
  • Track Clicks: Enables automatic tracking of user click actions
  • Track Scrolls: Enables automatic tracking of user scroll actions
  • Track Errors: Enables the tracking of JavaScript errors happening on your website


Another action the SDK template provides is the ability to record events. Events are a way to track any custom actions or other data you would like to track from your website. You may also set segments to be able to view a breakdown of the action by providing the segment values.

To record an event you would need to use the Record Event action in the template's drop down menu:

Here the Event Key is a mandatory value. It represents the name of the event that you will see in you Countly server. However, segmentation is optional key/value pairs you can send with the event if extra information would be needed.


Looking for help?