Google Analytics ট্যাগ রেফারেন্স

এই নথিটি প্রস্তাবিত Google Analytics ট্যাগ এবং বিকল্প অ্যাসিঙ্ক ট্যাগে থাকা কোডের একটি বিশদ ব্যাখ্যা প্রদান করে।

এই তথ্য শুধুমাত্র শিক্ষাগত উদ্দেশ্যে, সাধারণত ট্যাগটি তার ছোট আকারে ব্যবহার করা উচিত, কারণ এটি আপনার ব্যবহারকারীদের উপর সবচেয়ে ছোট কার্যক্ষমতার প্রভাব ফেলবে।

Google Analytics ট্যাগ

নিম্নলিখিত দুটি বিভাগে Google Analytics ট্যাগের সংক্ষিপ্ত এবং অমিনিফাইড সংস্করণগুলি দেখায়৷

Minifed সংস্করণ

<!-- Google Analytics -->
<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>
<!-- End Google Analytics -->

আনমিনিফেড সংস্করণ

<!-- Google Analytics -->
<script>
/**
 * Creates a temporary global ga object and loads analytics.js.
 * Parameters o, a, and m are all used internally. They could have been
 * declared using 'var', instead they are declared as parameters to save
 * 4 bytes ('var ').
 *
 * @param {Window}        i The global context object.
 * @param {HTMLDocument}  s The DOM document object.
 * @param {string}        o Must be 'script'.
 * @param {string}        g Protocol relative URL of the analytics.js script.
 * @param {string}        r Global name of analytics object. Defaults to 'ga'.
 * @param {HTMLElement}   a Async script tag.
 * @param {HTMLElement}   m First script tag in document.
 */
(function(i, s, o, g, r, a, m){
  i['GoogleAnalyticsObject'] = r; // Acts as a pointer to support renaming.

  // Creates an initial ga() function.
  // The queued commands will be executed once analytics.js loads.
  i[r] = i[r] || function() {
    (i[r].q = i[r].q || []).push(arguments)
  },

  // Sets the time (as an integer) this tag was executed.
  // Used for timing hits.
  i[r].l = 1 * new Date();

  // Insert the script tag asynchronously.
  // Inserts above current tag to prevent blocking in addition to using the
  // async attribute.
  a = s.createElement(o),
  m = s.getElementsByTagName(o)[0];
  a.async = 1;
  a.src = g;
  m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');

// Creates a default tracker with automatic cookie domain configuration.
ga('create', 'UA-XXXXX-Y', 'auto');

// Sends a pageview hit from the tracker just created.
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->

বিকল্প অ্যাসিঙ্ক ট্যাগ

নিম্নলিখিত দুটি বিভাগ বিকল্প অ্যাসিঙ্ক ট্যাগের ছোট এবং অমিনিফাইড সংস্করণ দেখায়। আপনি কোন কোড ব্যবহার করবেন তার বিশদ বিবরণের জন্য আপনার সাইটে analytics.js যোগ করা দেখুন।

সংক্ষিপ্ত সংস্করণ

<!-- Google Analytics -->
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics -->

আনমিনিফাইড সংস্করণ

<!-- Google Analytics -->
<script>
// Creates an initial ga() function.
// The queued commands will be executed once analytics.js loads.
window.ga = window.ga || function() {
  (ga.q = ga.q || []).push(arguments)
};

// Sets the time (as an integer) this tag was executed.
// Used for timing hits.
ga.l = +new Date;

// Creates a default tracker with automatic cookie domain configuration.
ga('create', 'UA-XXXXX-Y', 'auto');

// Sends a pageview hit from the tracker just created.
ga('send', 'pageview');
</script>

<!-- Sets the `async` attribute to load the script asynchronously. -->
<script async src='//www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics -->