I need to add google tag manager (Gtag) to all pages (modules) of the project. Gtag-code consists of 3 files:
- 2 files with js-code, that needs to be included in <head> tag,
- 1 file with <noscript> tags that need to be included in <body> tag.
Each module of my project contains layout.php and AppAsset.php. js-files in these layouts need to be included in <body> tag.
So, I created GlobalAppAsset.php, define $js-property there:
class GlobalAppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $js = [
'js/gtag_script1.js',
'js/gtag_script2.js',
];
public $jsOptions = ['position' => \yii\web\View::POS_HEAD];
}
AppAsset.php for each module in project I inherit from GlobalAppAsset.php and now I need to merge its $js with $js-property in GlobalAppAsset.php. How can I do it properly?
Also, I need that AppAsset.php's js-files be included in <body>-section of the layout, and GlobalAppAsset.php's $js-files be included in <head>-section. How can I this?
And finally, I need to include Gtag's php-file with <nonscript>-part of gtag in <body>. Is it possible to do it with Assets?