Social Details Google Analytics Widget

Latest Stable Version Latest Unstable Version Total Downloads Monthly Downloads Daily Downloads
Thankful to Krajee!
to get more out of us.

NOTE: This extension depends on the kartik-v/yii2-krajee-base extension which in turn depends on the yiisoft/yii2-bootstrap extension. Check the composer.json for this extension's requirements and dependencies that may be updated by composer.

This widget allows you to embed GoogleAnalytics plugin into your website.

The GoogleAnalytics widget supports these parameters.
  • id: string the Google Analytics Tracking ID

  • domain: string the domain name of your website where the tracking code will be displayed

  • objectName: string the global object name. Defaults to __gaTracker

  • testMode: boolean whether to enable test mode to automatically set `cookieDomain` to `none` for localhost. The test mode will auto default to YII_DEBUG definition.

  • anonymizeIp: int the settings to anonymize the IP address of the hit (http request) sent to Google Analytics. One of the following values are supported:

    • 0 or GoogleAnalytics::HIT_NONE: The IP will not be anonymized.

    • 1 or GoogleAnalytics::HIT_ALL: Anonymize the IP addresses for all the hits sent from a page (the lifetime of the tracker object).

    • 2 or GoogleAnalytics::HIT_EACH: Anonymize the IP addresses of an individual hit.

  • trackerConfig: array|string the tracker object configuration. Set it as a string (to be used as is) or an associative array in $key => $value format. Check the GoogleAnalytics tracker object create documentation for further details.

  • sendConfig: array|string the configuration for sending data. Set it as a string (to be used as is) or an associative array in $key => $value format. Check the GoogleAnalytics tracker object create documentation for further details.

  • jsBeforeSend: string any additional javascript to embed before the script that sends data.

  • jsAfterSend: string any additional javascript to embed after the script that sends data.

  • noscript: string|boolean text to be displayed if browser does not support javascript. If set to false will not displayed. Defaults to Please enable JavaScript to view the comments powered by google-analytics.

  • noscriptOptions: array the HTML attributes for the noscript message container. Defaults to ['class' => 'alert alert-danger']

NOTE You can configure the GoogleAnalytics settings once at the social module configuration level, for defaulting it across your application, and skip it in your widget calls. For example.
// your module config
'modules' => [
    'social' => [
        // the module class
        'class' => 'kartik\social\Module',

        // the global settings for the google-analytics widget
        'google-analytics' => [
            'id' => 'TRACKING_ID',
            'domain' => 'TRACKING_DOMAIN'
        ],
]

// your call in your view/layout file
echo GoogleAnalytics::widget([]); // will use the google-analytics settings configured in module

You can setup the GoogleAnalytics widget in your view layout file or your view like below:

use kartik\social\GoogleAnalytics;

// If any parameters are not passed, the widget will use settings 
// from the social module wherever possible
echo GoogleAnalytics::widget();

// Basic widget usage
echo GoogleAnalytics::widget([
    'id' => 'TRACKING_ID', 
    'domain' => 'TRACKING_DOMAIN',
]);

// Advanced widget usage
echo GoogleAnalytics::widget([
    'id' => 'TRACKING_ID', 
    'domain' => 'TRACKING_DOMAIN',
    'noscript' => 'Analytics cannot be run on this browser since Javascript is not enabled.'
]);