To migrate your Google Analytics data to Countly, follow these three steps:
- Integrate the Countly Web SDK: Add the Countly initialization snippet to your web page. You must provide your
Countly.app_key and your Countly.url. - Load the Adapter: Declare the
ga_adapter.js script after the Countly SDK has been integrated. - Initialize the Adapter: Call
CountlyGAAdapter() within your existing Google Analytics configuration block.
// 1. Countly SDK Integration
<script type='text/javascript'>
var Countly = Countly || {};
Countly.q = Countly.q || [];
Countly.onload = Countly.onload || [];
Countly.app_key = "YOUR_APP_KEY";
Countly.url = "https://yourdomain.com";
Countly.q.push(['track_sessions']);
Countly.q.push(['track_pageview']);
(function() {
var cly = document.createElement('script'); cly.type = 'text/javascript';
cly.async = true;
cly.src = 'https://cdn.jsdelivr.net/npm/countly-sdk-web@latest/lib/countly.min.js';
cly.onload = function(){Countly.init()};
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(cly, s);
})();
</script>
// 2. Declare the adapter script
<script src="../plugin/ga_adapter/ga_adapter.js"></script>
// 3. Update Google Analytics snippet
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
// Call the adapter
CountlyGAAdapter();
ga('create', 'UA-56295140-3', 'auto');
ga('send','event','category','action','label');
ga('send','pageview','page.html');
</script>