Adding Google Tag Manager Code

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Il y a 8 ans
Hi

I need to add google tag manager code after the <body>

I have tried the All in one plugin, but unfortunately this plugin wraps the tag manager code in a <div> that google does not like.

How else can I do it even if i have to do it manually?

Your help will be apprreciated

I have nop version 3.2
Il y a 8 ans
after <body> tag  and also before @RenderBody() code

Path: Themes\{yourThemeName}\Views\Shared\_Root.Head.cshtml
Il y a 8 ans
frogstar wrote:
Hi

I need to add google tag manager code after the <body>

I have tried the All in one plugin, but unfortunately this plugin wraps the tag manager code in a <div> that google does not like.

How else can I do it even if i have to do it manually?

Your help will be apprreciated

I have nop version 3.2

Do you want apply that in full website or some specific url?
Il y a 8 ans
@anik1991 I need it for the entire site.


sohel wrote:
after <body> tag  and also before @RenderBody() code

Path: Themes\{yourThemeName}\Views\Shared\_Root.Head.cshtml


thank you this worked.

Appreciate the quick response
Il y a 8 ans
frogstar wrote:
Hi

I need to add google tag manager code after the <body>

I have tried the All in one plugin, but unfortunately this plugin wraps the tag manager code in a <div> that google does not like.

How else can I do it even if i have to do it manually?

Your help will be apprreciated

I have nop version 3.2


hi
U can use all in one.
its an old version the new one supports javascript, but I guess it will work

1. create a new item set the widget zone and save.
2. go to Admin -> Configurations -> Settings -> All settings
3. Filter the string name field to allinone.htmlcode1
4. copy and past your code in the Value field of the allinone.htmlcode1

should work
Il y a 8 ans
hezyz wrote:
Hi

hi
U can use all in one.
its an old version the new one supports javascript, but I guess it will work

1. create a new item set the widget zone and save.
2. go to Admin -> Configurations -> Settings -> All settings
3. Filter the string name field to allinone.htmlcode1
4. copy and past your code in the Value field of the allinone.htmlcode1

should work


Thanks, I tried all in one it does place the script where you need it but it wraps the script in a <Div> which google tag manager doesn't like.
Il y a 8 ans
frogstar wrote:
Hi

hi
U can use all in one.
its an old version the new one supports javascript, but I guess it will work

1. create a new item set the widget zone and save.
2. go to Admin -> Configurations -> Settings -> All settings
3. Filter the string name field to allinone.htmlcode1
4. copy and past your code in the Value field of the allinone.htmlcode1

should work

Thanks, I tried all in one it does place the script where you need it but it wraps the script in a <Div> which google tag manager doesn't like.


if u do as I wrote above, the div will not be there.
Its a way to avoid adding the div tag
Il y a 8 ans
hezyz wrote:


if u do as I wrote above, the div will not be there.
Its a way to avoid adding the div tag



oh! understood, thank you
Il y a 4 ans
sohel wrote:
after <body> tag  and also before @RenderBody() code

Path: Th
emes\{yourThemeName}\Views\Shared\_Root.Head.cshtml


Please Advise this is correct ?

@using Nop.Core
@using Nop.Core.Domain;
@using Nop.Core.Domain.Common;
@using Nop.Core.Domain.Seo
@using Nop.Services.Events
@using Nop.Services.Localization
@using Nop.Services.Configuration;
@using Nop.Services.Security;
@using Nop.Web.Framework.Events

@inject CommonSettings commonSettings
@inject IEventPublisher eventPublisher
@inject IPermissionService permissionService
@inject IWorkContext workContext
@inject SeoSettings seoSettings
@inject StoreInformationSettings storeInformationSettings
@inject IStoreContext storeContext
@inject ISettingService settingService
@inject Nop.Services.Localization.ILanguageService languageService

@{
    Html.AppendScriptParts(ResourceLocation.Footer, "~/js/public.countryselect.js");
    var displayMiniProfiler = storeInformationSettings.DisplayMiniProfilerInPublicStore
            && (!storeInformationSettings.DisplayMiniProfilerForAdminOnly || permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel));

    Html.AppendScriptParts(ResourceLocation.Footer, "~/js/public.ajaxcart.js");
    Html.AppendScriptParts(ResourceLocation.Footer, "~/js/public.common.js");
    //when jQuery migrate script logging is active you will see the log in the browser console

    var iosFixFilePath = "~/Plugins/SevenSpikes.Core/Scripts/iOS-12-array-reverse-fix.min.js";
    var iosFixContentFilePath = CommonHelper.DefaultFileProvider.MapPath(iosFixFilePath);

    if(System.IO.File.Exists(iosFixContentFilePath))
    {        
      Html.AppendScriptParts(ResourceLocation.Footer, iosFixFilePath);
    }

    if (commonSettings.JqueryMigrateScriptLoggingActive)
    {
        Html.AppendScriptParts(ResourceLocation.Footer, "~/lib/jquery-migrate/jquery-migrate-3.0.1.js");
    }
    else
    {
        Html.AppendScriptParts(ResourceLocation.Footer, "~/lib/jquery-migrate/jquery-migrate-3.0.1.min.js");
    }
    Html.AppendScriptParts(ResourceLocation.Footer, "~/lib/jquery-ui/jquery-ui-1.12.1.custom/jquery-ui.min.js");
    Html.AppendScriptParts(ResourceLocation.Footer, "~/lib/jquery-validate/jquery.validate.unobtrusive-v3.2.10/jquery.validate.unobtrusive.min.js");
    Html.AppendScriptParts(ResourceLocation.Footer, "~/lib/jquery-validate/jquery.validate-v1.17.0/jquery.validate.min.js");
    Html.AppendScriptParts(ResourceLocation.Footer, "~/lib/jquery/jquery-3.3.1.min.js");

    //X-UA-Compatible tag
    if (commonSettings.RenderXuaCompatible)
    {
        Html.AppendHeadCustomParts($"<meta http-equiv=\"X-UA-Compatible\" content=\"{commonSettings.XuaCompatibleValue}\"/>");
    }
    //custom tag(s);

    if (!string.IsNullOrEmpty(seoSettings.CustomHeadTags))
    {
        Html.AppendHeadCustomParts(seoSettings.CustomHeadTags);
    }

    var storeId = storeContext.CurrentStore.Id;
    var themeColor = settingService.GetSettingByKey("venturethemesettings.themecolor", "dark-theme", storeId, true);

    var currentPageClass = (await Html.PartialAsync("_CurrentPageClass")).ToHtmlString().Trim();

    eventPublisher.Publish(new PageRenderingEvent(this.Html));
}
<!DOCTYPE html>
<html lang="@languageService.GetTwoLetterIsoLanguageName(workContext.WorkingLanguage)" @(this.ShouldUseRtlTheme() ? Html.Raw(" dir=\"rtl\"") : null) @Html.NopPageCssClasses()>
<head>
<!-- Google Tag Manager -->
<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','XXXXXXXXXX');</script>
<!-- End Google Tag Manager -->
    <title>@Html.NopTitle()</title>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
    <meta name="description" content="@(Html.NopMetaDescription())" />
    <meta name="keywords" content="@(Html.NopMetaKeywords())" />
    <meta name="generator" content="nopCommerce" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
    <link href="https://fonts.googleapis.com/css?family=Fjalla+One&amp;subset=latin-ext&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Lato&amp;subset=latin-ext&display=swap" rel="stylesheet">
    @Html.NopHeadCustom()
    @*This is used so that themes can inject content into the header*@
    @await Html.PartialAsync("Head")
    @await Component.InvokeAsync("Widget", new { widgetZone = PublicWidgetZones.HeadHtmlTag })
    @await Component.InvokeAsync("Widget", new { widgetZone = "head_html_tag_after_css_files_venture" })
    @Html.NopCssFiles(ResourceLocation.Head)
    @Html.NopScripts(ResourceLocation.Head)
    @Html.NopCanonicalUrls()
    @await Component.InvokeAsync("NewsRssHeaderLink")
    @await Component.InvokeAsync("BlogRssHeaderLink")
    @*Insert favicon and app icons head code*@
    @await Component.InvokeAsync("Favicon")
    @if (displayMiniProfiler)
    {
        <mini-profiler />
    }
    @Html.NopInlineScripts(ResourceLocation.Head)
    <!--Powered by nopCommerce - https://www.nopCommerce.com-->
</head>
<body class="@currentPageClass @themeColor">
    <div class="page-loader">
        <div class="loader"></div>
    </div>
    <!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=XXXXXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
    @RenderBody()
    @Html.NopCssFiles(ResourceLocation.Footer)
    @Html.NopScripts(ResourceLocation.Footer)
    @Html.NopInlineScripts(ResourceLocation.Footer)
    <div class="scroll-back-button" id="goToTop"></div>
</body>
</html>
Il y a 4 ans
Update on above code paste.

Error in code : Do not Add the Google Tag in Head section in Root.Head .
Only add the Body section in body tag
between </div> and @RenderBody()

Add the Google Head code via admin panel --> General Setting in Custom head section.

It will work then.

With Google Tag Running --> you can fire all Facebook Pixel and other scripts from Google Tag manager.

Thanks
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.