Analytics.js is a library developed in JavaScript by AFS Analytics in order to measure the traffic and analyze the behavior of visitors to a website.
AFS Analytics offers a library that is compatible with Google Analytics, which has the same structure and functions. This compatibility makes it easy to implement AFS Analytics for those accustomed to Google Analytics. At the end of this guide, a section is devoted to the difference between the JavaScript tracking snippet of Google and that of AFS Analytics, and how to replace it quickly.
The JavaScript tracking code, also called JavaScript tracking snippet consists of a few lines. It can be pasted between the <head> and </head> (highly recommended) or <body> and </body> HTML tags of your website pages.
The XXXXXXXX string must be replaced with your site identifier ID. This unique 8-digit number was created when you registered your website on AFS Analytics. You can also find it by choosing the Manage Websites option in the Account menu on the dashboard.
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['AfsAnalyticsObject']=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','//code.afsanalytics.com/js/analytics.js','aa');
aa('create', 'XXXXXXXX', 'auto');
aa('set','autotrack','dataset');
aa('send', 'pageview',);
</script>
The above code does the following:
The example above shows the basic implementation of AFS Analytics on a website. This JavaScript code may require changes or modifications dedicated to your website.
The aa() function offers numerous additional commands and parameters to help you to track more interactions.
Note:The HTML/JavaScript tracking code preceding the aa() function doesn’t need to be changed.
The above javacript code tracks by this data.
The new version no longer displays the AFS Logo on your website pages. However, if you want to display it, you have to specify its location by adding the following HTML code where you want the logo to appear:
<div id = 'afsanalytics'></ div>
Note: For the free version, this tag is useful if your traffic exceeds the limit.
For basic activity reports, implementing the previous JavaScript tracking code is sufficient. For an advanced and customized installation, meaning tracking the interactions of the visitors with the content of your site, it is advisable that you read the following guides:
There are three differences between the two codes.
Note: The definition of the https: protocol is optional.
Simply change a small portion of the Google code on your site page and keep the name of the call function:
<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');
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
To be replaced with:
<script>
(function(i,s,o,g,r,a,m){i['AfsAnalyticsObject']=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','//code.afsanalytics.com/js/analytics.js','ga');
ga('create', 'XXXXXXXX', 'auto');
ga('send', 'pageview');
</script>
Note: Don’t forget to replace XXXXXXXX with the identifier ID of your website.
All calls to the analytics.js library are done using the ga() command. You can add the autotrack command to set the events tracking mode:
ga('create', 'XXXXXXXX', 'auto');
ga('set','autotrack','dataset');
ga('send', 'pageview');