Add (composer): Add gtm library

This commit is contained in:
2023-07-30 14:50:28 +08:00
parent ac581a56b2
commit 0a520d6347
7 changed files with 122 additions and 3 deletions

View File

@@ -37,6 +37,7 @@ class Kernel extends HttpKernel
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\StoreGeoSession::class,
\Spatie\GoogleTagManager\GoogleTagManagerMiddleware::class,
],
'api' => [

View File

@@ -21,9 +21,10 @@
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.8",
"laravel/ui": "^4.0",
"league/flysystem-aws-s3-v3": "^3.0",
"spatie/laravel-googletagmanager": "^2.6",
"stevebauman/location": "^7.0",
"tightenco/ziggy": "^1.6",
"league/flysystem-aws-s3-v3": "^3.0"
"tightenco/ziggy": "^1.6"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.8",

70
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "a0cadb98cfe6b8b1794e8816dbe50752",
"content-hash": "857339222c2e6de7077f733ec16a55f4",
"packages": [
{
"name": "alaminfirdows/laravel-editorjs",
@@ -4137,6 +4137,74 @@
],
"time": "2023-04-15T23:01:58+00:00"
},
{
"name": "spatie/laravel-googletagmanager",
"version": "2.6.6",
"source": {
"type": "git",
"url": "https://github.com/spatie/laravel-googletagmanager.git",
"reference": "19f257e203c0a3547328f142acf31a99ad895378"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/laravel-googletagmanager/zipball/19f257e203c0a3547328f142acf31a99ad895378",
"reference": "19f257e203c0a3547328f142acf31a99ad895378",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
},
"laravel": {
"providers": [
"Spatie\\GoogleTagManager\\GoogleTagManagerServiceProvider"
],
"aliases": {
"GoogleTagManager": "Spatie\\GoogleTagManager\\GoogleTagManagerFacade"
}
}
},
"autoload": {
"psr-4": {
"Spatie\\GoogleTagManager\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Sebastian De Deyne",
"email": "sebastian@spatie.be",
"homepage": "https://spatie.be",
"role": "Developer"
}
],
"description": "Google Tag Manager integration for Laravel",
"homepage": "https://github.com/spatie/laravel-googletagmanager",
"keywords": [
"Google Tag Manager",
"laravel",
"laravel-googletagmanager",
"spatie"
],
"support": {
"issues": "https://github.com/spatie/laravel-googletagmanager/issues",
"source": "https://github.com/spatie/laravel-googletagmanager/tree/2.6.6"
},
"funding": [
{
"url": "https://github.com/spatie",
"type": "github"
}
],
"time": "2021-12-15T10:28:22+00:00"
},
{
"name": "stevebauman/location",
"version": "v7.0.0",

View File

@@ -0,0 +1,27 @@
<?php
return [
/*
* The Google Tag Manager id, should be a code that looks something like "gtm-xxxx".
*/
'id' => env('GOOGLE_TAG_MANAGER_ID', ''),
/*
* Enable or disable script rendering. Useful for local development.
*/
'enabled' => env('GOOGLE_TAG_MANAGER_ENABLED', true),
/*
* If you want to use some macro's you 'll probably store them
* in a dedicated file. You can optionally define the path
* to that file here and we will load it for you.
*/
'macroPath' => env('GOOGLE_TAG_MANAGER_MACRO_PATH', ''),
/*
* The key under which data is saved to the session with flash.
*/
'sessionKey' => env('GOOGLE_TAG_MANAGER_SESSION_KEY', '_googleTagManager'),
];

View File

@@ -0,0 +1,4 @@
@if($enabled)
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id={{ $id }}"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
@endif

View File

@@ -0,0 +1,16 @@
@if($enabled)
<script>
window.dataLayer = window.dataLayer || [];
@unless(empty($dataLayer->toArray()))
window.dataLayer.push({!! $dataLayer->toJson() !!});
@endunless
@foreach($pushData as $item)
window.dataLayer.push({!! $item->toJson() !!});
@endforeach
</script>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','{{ $id }}');</script>
@endif

View File

@@ -0,0 +1,2 @@
@include('googletagmanager::head')
@include('googletagmanager::body')