-
-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Google Tag Manager #23
Comments
Hi, |
Hi @unaizp, have you made it work? |
I was able to make this workaround, based on the This is quick solution, don't use this without more reserach which cookies has to be mentioned <?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Whitecube\LaravelCookieConsent\Consent;
use Whitecube\LaravelCookieConsent\Facades\Cookies;
use Whitecube\LaravelCookieConsent\Cookie;
use Whitecube\LaravelCookieConsent\CookiesGroup;
class CookieServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
//
}
/**
* Bootstrap services.
*/
public function boot(): void
{
Cookies::essentials()
->session()
->csrf();
if (config('cookieconsent.google.analyticsId') != null) {
Cookies::analytics()
->google(config('cookieconsent.google.analyticsId'));
} else if (config('cookieconsent.google.gtmId') != null) {
Cookies::analytics()
->group(function (CookiesGroup $group) {
$group->name('gtm')
->cookie(
fn (Cookie $cookie) => $cookie->name('_ga')
->duration(2 * 365 * 24 * 60)
->description(__('cookieConsent::cookies.defaults._ga'))
)
->cookie(
fn (Cookie $cookie) => $cookie->name('_gid')
->duration(24 * 60)
->description(__('cookieConsent::cookies.defaults._gid'))
)
->cookie(
fn (Cookie $cookie) => $cookie->name('_gat')
->duration(1)
->description(__('cookieConsent::cookies.defaults._gat'))
)
->accepted(function (Consent $consent) {
$id = config('cookieconsent.google.gtmId');
$consent->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>');
});
});
}
}
}
This is quick solution, don't use this without more reserach which cookies has to be mentioned |
Just wanted to add my two cents here. One of our clients uses Google Tag Manager as well and we had some feedback from the marketing company about being unable to get Tag Assistant by Google connected. Upon review, and this issue, I noticed the difference in JS code that was being injected. What Laravel Cookie Consent does is inject gtag code:
Whereas you would want the Google Tag Manager code in case you use GTM:
I can setup a PR including a new |
I suppose this answers the question:
I'll draft a PR that creates a |
Sounds nice! Thanks @joshuadegier 🙂 |
I've tried to create a setup today, but not quiet happy with the outcome yet. Compared to the gtag code (or the gtag injected by the GTM code) the GTM code itself sets no cookies. In the example above by @MediKathi it injects the GTM code after acceptance but I'd rather have it injected on pageload and see if there is a way to have this plugin inject a GTM config that follows up loading the accepted tags. See this link for some more info. The code I think is needed, one way or another, is something like this:
If anybody has some more background information about the working of GTM I'd gladly accept some help. It's a first time for me diving deeper in this than just having a consent popup that injects a gtag. |
Hi, From my understanding using google documentation here it must done in 2 parts:
I am currently looking to see if "google consent mode v2" requires express events from denied to granted in order to load the tags properly. Anyway with a javascript event is also more convenient since we don't need to reload the page after the consents are given. |
Thanks for adding a few examples! I haven't found time to proceed on the code I'm working on. As far as I can see this would require adding a little bit of js code to the package in order to fire the events without pageload. I agree that this would be a cleaner option compared to refreshing the page. Any ideas on whether we need to separate the consent that is given for user data / personalization / storage / analytics storage? |
Yes it needs to be separated, depending what other codes are you delivering trough google tag manager. I am stuck in project for the next couple of days, then i plan to try and see if can push a pr. |
Hey, any idea when support for new policies will be added, so we can have the consent with GTM, our team is experienceing issues, google says we do not pass those policies, and I really do not want to implement the GTM consent as well as this vendor package. Thanks. |
@florinche were you able to create a PR for this? Issue is that there is no gtag denied prior to injecting the code so the consent is not necessarily viable, it works if you consent. It should be applied to the prior to consenting as denied:
Apologies if I am misunderstanding. |
@juliancarstairs unfortunately not. Though i made it pass with various customizations on our platform we still ended up getting "hit" really hard in google ads by their rules to have "Google Consent Mode v2" We had to turn to one of their google certified cmp partners (we got spammed on daily basis, basically felt forced to use one of theirs) just to pass the same diagnostics we passed before using custom implementation. I have zero time for the next weeks. :( |
Google Tag Manager itself doesnt use Cookies. What i did was i added GTM code to head and body as needed to every page. In header, before GTM code, i added:
After GTM code i added:
And in CookieServiceProvider i added:
Im not sure how "right" this is, but it works. |
Hello, this is a fantastic script for Laravel.
I use Google Tag Manager instead GA4 and dont't know how to create a custom code for this script.
Searched the manual and can't find anything.
¿How can I Use this type of code?
<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','GTM-XXXXXX');</script>
Thanks in advance
The text was updated successfully, but these errors were encountered: