File: plugin/ga_adapter/

Recommend this page to a friend!
  Classes of Arturs Sosins   Countly Web SDK   plugin/ga_adapter/   Download  
File: plugin/ga_adapter/
Role: Example script
Content type: text/markdown
Description: Example script
Class: Countly Web SDK
Track site accesses and errors the Countly API
Author: By
Last change: [878] ga_adapter (#241)

* refactored ga adapter

* doc

* doc
[872] Codacy fixes (#235)

* fix: Avoid trailing commas in object or array literals

* fix: Avoid trailing commas in object or array literals

* no comma rule added and linted

* new line fix

* mdown lint

* increased the scope of the markdown and added a markdownignore

* got rid of empty lines after list itms

* line ending reacty

* staging and linting

* reveng ga

* lf

* lintt conf

* Update .markdownlint.json

* 25true

* changes

Co-authored-by: ArtursKadikis <>
Date: 9 months ago
Size: 2,764 bytes


Class file image Download

Countly Google Analytics Adapter

What's Countly Google Analytics Adapter?

Countly Google Analytics Adapter is a migration tool for your web apps which has already implemented Google Analytics trackers, you can easily send your analytics data to your Countly instance too without any extra integration.

Implementing Countly Google Analytics Adapter in your web pages

There are only two step for integration.

1. Add Countly Web SDK integration snippet into your web page

<script type='text/javascript'>
// Some default pre init
var Countly = Countly || {};
Countly.q = Countly.q || [];
Countly.onload = Countly.onload || [];

// Provide your app key that you retrieved from Countly dashboard
Countly.app_key = "YOUR_APP_KEY";

// Provide your server IP or name. Use or 
// or for EE trial server.
// If you use your own server, make sure you have https enabled if you use
// https below.
Countly.url = ""; 

// Start pushing function calls to queue
// Track sessions automatically (recommended)
//track web page views automatically (recommended)
// Uncomment the following line to track web heatmaps (Enterprise Edition)
// Countly.q.push(['track_clicks']);

// Uncomment the following line to track web scrollmaps (Enterprise Edition)
// Countly.q.push(['track_scrolls']);
// Load Countly script asynchronously
(function() {
 var cly = document.createElement('script'); cly.type = 'text/javascript'; 
 cly.async = true;
 // Enter url of script here (see below for other option)
 cly.src = '';
 cly.onload = function(){Countly.init()};
 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(cly, s);

2. Declare your plugin's script after integrating Countly

<script src="../plugin/ga_adapter/ga_adapter.js"></script>

3. Change your Google Analytics integration code like below

(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

// add this line into your google analytics snippet

ga('create', 'UA-56295140-3', 'auto');


That's all. Now you can track your app from your Countly instance too. You can check examples folder for an implementation example.