Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Så här installerar och hanterar du Google Tag Manager i WordPress

Vill du installera Google Tag Manager i WordPress?

Google Tag Manager låter dig add tracking code snippets till din WordPress website. Det är ett gratis tools och allow you to track different user interactions.

I den här artikeln visar vi hur du installerar och konfigurerar Google Tag Manager i WordPress på rätt sätt och förklarar fördelarna.

how to install and setup Google Tag Manager in WordPress

Vad är Google Tag Manager?

Google Tag Manager (GTM) är ett gratis verktyg från Google som låter dig lägga till, uppdatera och hantera code snippets som anropas taggar på din WordPress site.

Ofta behöver webbplatsägare lägga till flera code snippets för att spåra sina konverteringar, formulärinlämningar, link clicks och samla in andra analytiska data på sin website. Med Google Tag Manager kan du enkelt lägga till och hantera alla dessa skript från en enda dashboard.

Det finns built-in tagged templates för Google Analytics, Google Ads, Google Optimize, DoubleClick och Google AdSense. Tag Manager fungerar också med flera tredjepartsplattformar för analys och tracking.

Detta saved you tiden för att lägga till och ta bort taggar från din kod i stället för att hantera den från en enkel dashpanel. Eller ej, alla dessa separata snippor hämtar du i ett enda skript.

Med detta sagt, låt oss se hur du addar Google Tag Manager till WordPress. Vi kommer också att visa dig en alternativ metod för att spåra olika interaktioner mellan användare på din site. Det bästa är att du inte behöver editera kod eller ställa in taggar.

Klicka bara på länkarna under för att hoppa vidare till din önskade section:

Lägga till Google Tag Manager i WordPress

Först måste du besöka Google Tag Manager-webbplatsen och klicka på knappen ”Starta gratis” för att registrera dig.

Google Tag Manager website

När du har loggat in kommer du till sidan add new account.

Gå vidare och klicka på knappen ”Create Account”.

Create account in tag manager

Därefter kan du enter ett namn för ditt account och välja ett land från dropdown-menyn.

Google Tag Manager ger dig också alternativet att dela data anonymt med Google. Du kan helt enkelt klicka på checkboxen och rulla ner.

Enter account name and country

Nu måste du add to en container till your account. En container kan vara en website, iOS- eller Android-appar eller en server. I det här fallet kommer vi att använda alternativet ”Web”.

You can use your site’s domain for the container name. När du är klar klickar du på knappen ”Skapa” för att fortsätta.

Enter container name and select platform

Du kommer nu att se ett nytt fönster glida in från höger med Google Tag Manager-avtalet om användarvillkor.

Du kan klicka på checkboxen längst ner för att godkänna villkoren för behandling av personuppgifter och sedan klicka på knappen ”Yes” högst upp.

Accept tag manager terms of agreement

Google Tag Manager kommer nu att skapa ditt account.

Därefter kommer det nu att visa dig trackingkoder som du behöver add till din site.

Copy tag manager code

Kopiera bara dessa 2 koder, eftersom du kommer att behöva lägga till dem i header och body section på din WordPress website.

Lägga till Google Tag Manager-kod till WordPress

Det enklaste sättet att lägga till code snippets i WordPress är att använda WPCode plugin. Det är det bästa WordPress code snippet plugin och låter dig lägga till och hantera olika custom codes på din website.

Det bästa är att du kan komma igång gratis med WPCode. Men det finns också en premiumversion som erbjuder fler funktioner som ett code snippet bibliotek, villkorlig logik, auto-insert snippets, och mer.

Först måste du installera och aktivera det gratis pluginet WPCode. Om du behöver hjälp kan du vänligen läsa vår guide om hur du installerar ett plugin för WordPress.

När du har aktiverat måste du besöka Code Snippets ” Rubriker & Footers page från WordPress adminpanel. Nu ska du enter de koder som du kopierade tidigare.

Se till att du klistrar in <head>-koden i fältet Header och <body>-koden i fältet Body, som du kan se under.

Add header and body tag manager codes

När du är klar, glöm inte att clicka på knappen ”Save Changes”.

Google Tag Manager är nu redo att användas på din WordPress website.

Skapa en ny Tag i Google Tag Manager

Därefter kan du skapa en new tag i Google Tag Manager och ställa in tracking på din WordPress website.

Låt oss säga att du vill add to Google Analytics 4 (GA4) till din WordPress website med hjälp av Google Tag Manager.

Först måste du klicka på alternativet ”Add a new tag” från din dashboard för Tag Manager.

Create a new tag

Därefter kan du högst upp ange ett namn för din tagged.

Härifrån klickar du bara på alternativet ”Konfigurera taggar”.

Enter a title and click tag configuration

Därefter kommer Tag Manager att visa dig olika taggtyper att välja mellan.

I instance, this will include tags for Google Analytics, Google Ads, Floodlight, and more. Vi kommer att välja ”Google Analytics: GA4 Configuration” för denna tutorial.

Select a tag type

Därefter måste du enter detaljerna för din tag.

Först kan du add to mätningens ID:n.

Enter measurement ID

Du kan hitta mätnings-ID:n genom att logga in på ditt Google Analytics account.

Helt enkelt head till Admin ” Alternativet Data Streams under Property Column. Gå vidare och klicka på dina dataströmmar för att view mätningen ID:n.

Select your data stream

När ett new fönster öppnas bör du se Measurement ID:n högst upp i högra hörnet.

Du kan helt enkelt kopiera ID:n.

Copy your Measurement ID

Gå nu tillbaka till fönstret eller tabben Google Tag Manager och enter mätnings-ID.

Efter det kan du rulla ner och klicka på alternativet ”Triggering”.

Add a trigger

Google Tag Manager kommer nu att visa built-in triggers att välja mellan.

Gå vidare och välj alternativet ”Initialization – All Pages”.

Select initialization all page trigger

När du har valt utlösaren måste du store dina settings.

Klicka bara på knappen ”Save” högst upp i högra hörnet.

Save your GA4 tag

You should now see your newly created tag.

Gå vidare och klicka på knappen ”Submit” för att run taggen.

Preview and submit your tag

Ställ in avancerad tracking med hjälp av MonsterInsights (användarvänligt sätt)

Nu när du vet hur du installerar och använder Google Tag Manager kan du använda ett enklare sätt att ställa in avancerad tracking på din WordPress site.

Med MonsterInsights behöver du inte utföra komplicerade inställningar i GTM. Det är det bästa Google Analytics-pluginet för WordPress och konfigurerar automatiskt avancerad tracking åt dig. You behöver inte heller oroa dig för att göra ett misstag som kan förstöra dina tracking-data.

Det bästa av allt är att MonsterInsights visar rapporter i din WordPress dashboard. You won’t have to leave your site to see its performance. Den presenterar data som är viktiga för your business och hjälper till att avslöja insikter.

För denna tutorial kommer vi att använda MonsterInsights Pro-versionen eftersom den innehåller avancerade funktioner för tracking och premium addons. Det finns också en MonsterInsights Lite-version som du kan använda för att komma igång gratis.

Först måste du installera och aktivera pluginet MonsterInsights. Om du behöver hjälp, vänligen se vår guide om hur du installerar ett plugin för WordPress.

Efter aktivering kommer du att se MonsterInsights välkomstvy. Du kan klicka på knappen ”Launch the Wizard” och följa stegen på skärmen för att konfigurera Google Analytics.

Launch setup wizard

För mer detaljer, vänligen se vår guide om hur du installerar Google Analytics i WordPress.

MonsterInsights fungerar direkt ur boxen och lägger automatiskt till tracking i Google Analytics.

Här är några av de funktioner för tracking som tillägget erbjuder:

1. Track Clicks på länkar och knappar

MonsterInsights ställer in spårning av link click och knapp click direkt från boxen på din website. Google Analytics spårar inte link clicks som standard, och du måste använda GTM för att add to tracking.

Instance, you can track affiliate performance and see which links users click the most. På så sätt kan du öka dina intäkter genom att främja affiliates som får många clicks.

Outbound and affiliate links report

På samma sätt spårar pluginet också klick på utgående länkar. Dessa är links till andra webbplatser på din site. Du kan använda dessa data för att skapa nya partnerskap, registrera dig för ett affiliate-program och skapa nytt content på din egen site.

Förutom det hjälper MonsterInsights också till att spåra telefonlänkar, filnedladdningar, klick på CTA-knappar (call-to-action) och mer.

2. Ställ in ecommerce tracking i WordPress

Om du har en online-butik hjälper MonsterInsights dig att spåra dess prestanda utan att redigera spårningsskriptet eller använda Google Tag Manager.

Det erbjuder ett addon för ecommerce som låter dig aktivera tracking av ecommerce i WordPress med bara några clicks. You can see your site’s overall conversion rate, transactions, revenue, average order value, top-selling products, and much more.

Ecommerce overview report in MonsterInsights

För mer detaljer, vänligen se vår guide om hur man korrekt ställer in ecommerce tracking i WordPress.

3. Konfigurera spårning av formulärkonverteringar

Med MonsterInsights kan du också ställa in spårning av konvertering av formulär i Google Analytics. Pluginet erbjuder ett Forms addon som automatiskt spårar WordPress-formulär på din site.

Om du använder Google Tag Manager måste du skapa separata taggar för alla dina formulär och track dem i Google Analytics.

MonsterInsights gör dock denna process superenkel. Dessutom kan du viewa data i WordPress dashboard.

Forms report

4. Aktivera automatiskt Scrolling Depth Tracking

Har du någonsin undrat hur långt folk rullar på din webbsida innan de lämnar din site? Scrolling Depth tracking visar exakt det och hjälper you att placera dina bannerannonser och CTA:er på rätt ställe för att öka konverteringen.

MonsterInsights aktiverar automatiskt rulla tracking på din website. Det finns inget behov av ytterligare inställningar med Google Tag Manager eller att ändra tracking-koden kl.

Scroll tracking

Du kan läsa vår guide om hur du lägger till scrolling Depth tracking i WordPress med Google Analytics.

Vi hoppas att den här artikeln hjälpte dig att lära dig hur du installerar och konfigurerar Google Tag Manager i WordPress. Du kanske också vill se vår guide om den ultimata guiden till sökmotorsoptimering i WordPress och den bästa chattsupporten för småföretag.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Avslöjande: Vårt innehåll stöds av våra läsare. Det innebär att om du klickar på några av våra länkar, kan vi tjäna en provision. Se hur WPBeginner finansieras, varför det är viktigt, och hur du kan stödja oss. Här är vår editoriala process.

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

Den ultimata WordPress-verktygslådan

Få GRATIS tillgång till vår verktygslåda - en samling WordPress-relaterade produkter och resurser som varje professionell användare bör ha!

Reader Interactions

53 kommentarerLämna ett svar

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Moinuddin Waheed says

    Google tag manager aka GTM is such a powerful tool that enables tracking Google ads, Google analytics, Google optimize and Google Adsense all with the help of a snippet. This is really helpful in terms of tracking and making informed decision about different aspect of the blog and business.
    Both the methods mentioned is easy to implement and gets the GTM working for us. The second method with the plugin is better option for beginners like us. Thanks for bringing such an insightful article.

  3. prakhar sahu says

    as a beginner, this post was given to me from siteground guy to help me and thanks to you as well .thankyou

  4. Jasper says

    Hi there,

    This solution works as a charm, thanks a lot. I have 1 issue though: All the way at the bottom of all my site pages there is now a white bar with the text ”Javascript” written inside it on the left side of the screen.

    How can I remove that?

    • WPBeginner Support says

      You may want to make sure you copied the entire code as that normally means javascript code you’ve added to your site may have an error.

      Administratör

  5. Ann says

    I’d rather not install more plugins than I need. My theme allows me to paste the GTM code with the GA tag in my header. However, how do I get the body code in my page? Do i just use a text field high up on my HOME page and paste it in there? Thanks!

    • Nitesh S says

      Hey Ann,

      I know I’m late to reply but I’d highly recommend you install the plugin.

      Without it, you won’t be able to send detailed information to GA. I.e. If it’s an eCommerce – you won’t be able to receive product information, GTM on it’s own will give you extremely basic data and you’ll need to configure it entirely yourself which believe me takes weeks!

  6. Naji Boutros says

    Google Tag manager specifically says to post a portion of the code in the body of the webpage. Nothing I find on implementing Google Tag manager addresses this. Why is that?

    • adrian says

      The video hasn’t been updated in a while. What you have to do is put the 2nd half of the code in the footer section of the plugin, which actually places it in the body section. If you look at the plugin in wordpress it says ”These scripts will be printed above the tag.”

      Anything above ” is going to be in the body section.

  7. Deelip Kushwaha says

    Hi Admin,

    I don’t have good knowledge on WordPress.
    I am using WordPress theme for my website. And want to add google tag manager in my website. Can you please tell me how can I add tag manager code in WordPress Child theme. I am waiting for your positive response.

  8. NM says

    Where shoud I put ”Additionally, paste this code immediately after the opening tag” on Header and Footer Plugin ?

  9. Aswani says

    Wonderful guide. I got one major confusion cleared now – whether to add google analytics code first and then add google tag manager tags. Thanks a lot for this awesome help. A big time saver.

  10. Rob Wood says

    Hi,

    There is two elements to Google Tag Manager install

    1) in Header
    2) in Body

    Will you update your explanation to show the solution for this?

  11. AJ says

    Also, there’s another piece of code besides the code you mention here. They ask you to ”Paste this code as high in the of the page as possible:”, and the code is:


    (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’);

    Can I install both pieces of code in the header, right next to each other?

    Thanks!

    • Anthony says

      Yes, Google has changed this very recently. I want this also up-to-date and by Function.php instead of a plugin. Anybody???

  12. AJ says

    Hi, can I have both GA and GTM in the code at the same time? Or I have to remove GA if I’m installing GTM?

    Thanks!

    • Kevin says

      Hi AJ,

      you can have both (GA + GTM) in the code at the same time. No worries. Although it is more convenient to fire the GA snippet also through GTM. Google provides good instructions how to do that:

  13. Alessandro Marengo says

    Am I wrong or there is a bit of lack of support for your plugin on wordpress forum? It’s a pity… :(

  14. Murray says

    Great tutorial – I love you guys. I read it through and then read all the comments. Got my answers. Installed it etc and then checked my site by browsing from my smartphone.
    Everything is working great!

    No questions, just a big thankyou.
    Well done :)

  15. Gaurav Singh says

    I got This completely, But I have a confusion about there is my analytics code exist to how can I both through plugin insert header & Footer.

  16. Catherine says

    I’m very new to Google Tag Manager, this is the easiest tutorial I’ve found so far without the confusion.
    However I’m wondering if there is a conflict with having both GA code and GTM code on my website?
    There is a place on my wordpress theme to insert the Google Analytics code for tracking which I have always had.
    I have now inserted the Google Tag Manager code to the header php on my site so should I remove the original Google Analytics code or does that stay?
    Many Thanks,
    Catherine

  17. Lisa Smith says

    Thank you for making the plugin Multisite compatible!

    I see Google Tag Manager says to place the code immediately after the opening tag, but the plugin places it inside the tag. Will it still work if placed in the head rather than body?

  18. AJ Levinson says

    Thank you so much for this excellent tutorial.

    I am confused about a potential conflict with this method. Can you please help?

    Google Tag Manager says that the code can not be in the header. They want it right after the tag. But, if I use the Insert Headers and Footers plugin and paste the code there, won’t it put the Tag Manager code in the Header? Won’t this cause a conflict?

    In the paragraph, you wrote: ”If you do not wish to install a plugin, then you can also add the Google Tag Manager code in your WordPress theme or Child theme. Simply edit the header.php template and paste the code right after tag.” Is there a step-by-step on how to do this?

    • Jason says

      You might have wondered why Google so forcefully recommends that you place the container snippet just after the opening tag. There are two good reasons to do so.

      First, if you add the tag as well (as you should), this should always be in the body of the document. The tag (which is shown for browsers without JavaScript enabled) contains an iFrame which loads the GTM library. If you add the tag into the head of your document, it can perform pretty wildly with some browsers. You could experiment with leaving the in the body, and placing the JavaScript in the , but I haven’t tested it and certainly don’t recommend it.

      The second reason is simple: to maximize data collection, the snippet should be the first thing loaded when the body of the page is rendered. Because the library is loaded asynchronously, there’s no reason to delay it at all. So have it load as the first thing when the body is rendered, so that you don’t risk losing any data due to sluggish DOM elements delaying the page load.

      • Vince Outlaw says

        So, if you want it to load right after the tag, then is seems like you can’t use the Insert Headers and Footers plugin because the only options are in the (nope) and right before the tag (so at the end of loading, nope).

        Am I reading this right?

  19. steve says

    Curious about duel installs, of both, on WordPress — I know you have to have both accounts setup in google, but does the tag manager, in effect, *replace* the GA plugin we’ve been using for a few years?

    Or, does one still install both the GA plugin AND the tag manager plugin? Seems redundant, or perhaps I’m not understanding things clearly.

    Just trying to know the most efficient way to get all the analytics I enjoy now, and all the tag manager analytics as well.

    Thanks,
    S

    • WPBeginner Support says

      Tag Manager is not an analytics solution in itself. It just provides an easier way to add analytics tracking in your WordPress site. If you add Google Analytics by adding it through a tag in tag manager than you can safely uninstall Google Analytics plugin on your WordPress site.

      Administratör

  20. Marcelo says

    Sorry i might be slower to understand, but what is the difference between google analytic and tag manager ? I mean, what am i missing using analytic only ?

    • WPBeginner Support says

      Google Tag Manager simply makes it easier to add analytics, manage and track events, and add third party scripts to your website. Tag Manager is not an alternate to analytics.

      Administratör

  21. Susan Meko says

    What a detailed and step by step guide on GTM. I just completed my training on this and now I am completely clear on this.
    I believe it has nothing to do with SEO and ranking, it is just for managing all the tags we could us on our website.

    Regards
    Susan Meko

  22. Kabelo says

    Hi, may I ask. I have two wordpress installed in one domain. eg: http://www.wp1.com/wp2.

    Will tracking wp1 be able to give me the stats of w2. If not, how may I achieve that?

    Looking forward to your response.

    Thank you in advance.

  23. DOK Simon says

    That is great , simple tutorial with details. A friend told me about it but didn’t explain to this extent … Please apart from managing all script in a single dashboard does it in anyway improve the site SEO…. ??

  24. Saeed Khan says

    Brother your article is very informative. Can we used google analytics and google tag manager code together?

Lämna ett svar

Tack för att du väljer att lämna en kommentar. Tänk på att alla kommentarer modereras enligt våra policy för kommentarer, och din e-postadress kommer INTE att publiceras. Vänligen använd INTE nyckelord i namnfältet. Låt oss ha en personlig och meningsfull konversation.