دمج Google Tag Manager مع Google Analytics

:bookmark: This guide will help you set up Google Tag Manager and use it with Google Analytics on your Discourse site. Additionally, it covers configuring variables, triggers, and tags in Google Tag Manager to track page views.

:information_source: This guide covers setting up Google Tag Manager. If you only want to enable Google Analytics for your site, set the G-Tag in the ga universal tracking code site setting. Our settings may still refer to all analytics as universal, but this is a legacy field naming artifact. The following instructions use, and work for, Google Tags.

:person_raising_hand: Required user level: Administrator

Integrating Google Tag Manager (GTM) with Google Analytics (GA) allows you to manage and track events on your Discourse site effectively. This guide covers the full setup process, from creating a GA account to configuring GTM with the necessary tags and triggers.

Summary

  1. Create a Google Analytics account and property.
  2. Set up Google Tag Manager.
  3. Configure GTM variables, triggers, and tags.
  4. Integrate GTM with your Discourse site.

Create a Google Analytics account

  1. Visit Google Analytics and sign in with your Google account.

  2. If you don’t have an account yet, follow the guided steps to create one.

  3. Create a property by clicking on “Admin” and then “Create Property”.

  4. Fill in the required details on the “Property creation” screen.

  5. Enter your business details on the next screen.

  6. Select your business objectives appropriately.

:information_source: Info: Selecting the four sections will most closely match the reports Analytics has typically provided:


7. Choose “Web” as the platform for data collection.

  1. Set up a data stream by entering your site’s URL and a stream name.

:information_source: After successfully creating your web stream, make a note of your Measurement ID. You’ll need this for GTM setup.

Set up Google Tag Manager

  1. Visit Google Tag Manager and create an account.
  2. Set up a container by following the guided steps, and choose “Web” as the platform.

Configure GTM

Variables

  1. Go to the “Variables” tab in GTM and click “New” in the User-Defined Variables section.
  2. Create two Data Layer Variables:
  • Title: DL-page-title
    Type: Data Layer Variable
    Data Layer Variable Name: page.title
    Data Layer Version: 2

  • Title: DL-page-url
    Type: Data Layer Variable
    Data Layer Variable Name: page.url
    Data Layer Version: 2

As an example, choose the variable type:

Then configure the variables, as in this example:

Triggers

  1. Go to the “Triggers” tab and click “New”.

  2. Choose “Custom Event” as the type.

  3. Name the trigger virtualPageView and Save it.

    The end result should look like this:

Tags

  1. Go to the “Tags” tab and create a new tag.

  2. Choose Google Analytics: Google Tag as the tag type.

  3. Configure the tag with the following details:

  • Measurement ID: Enter your Measurement ID from GA.
  • Required Fields to Set:
    • title: {{DL-page-title}}
    • page: {{DL-page-url}}
    • send_page_view: true
    • page_path: {{Page Path}}

When finished it should look like this (note that you can add a userID parameter in addition to the parameters above, but you will need to add an additional variable like DL-page-url.):

  1. Choose the virtualPageView trigger for this tag.
  2. Name your tag and Save it.

Publish your GTM workspace

Publish your container in GTM by clicking the blue “Submit” button in the upper-right corner of the page.

:warning: Important: If you encounter 404 errors from googletagmanager.com, ensure your GTM container changes have been published.

Integrate GTM with Discourse

  1. Go to your Discourse Admin settings and search for gtm container id.
  2. Enter your GTM Container ID (format: GTM-XXXXXX) in the corresponding field.

:warning: Note: Remove any existing Analytics tracking code from the ga universal tracking code and ga tracking code settings in Discourse.

Reload your site and check the Real-Time content view in GA to confirm that data is flowing through GTM.

Additional Uses

With GTM, you can add more tags to track additional events such as:

Related Links

Last edited by @jessii 2024-08-03T01:04:37Z

Check documentPerform check on document:
46 إعجابًا

كما هو مذكور، تمت إزالة علامة تكوين GA4 وستختار الآن علامة Google. تظل خطوات الإعداد كما هي، ولكنني قمت بتحديث الوثائق.

بالنسبة لأي شخص قام بإعداد علامة GA4 سابقًا، كان ينبغي تحديثها تلقائيًا ولا تتطلب أي تغييرات من جانبك.

تجدر الإشارة إلى أن هذا ليس إعدادًا مثاليًا من حيث أفضل ممارسات GA4/GTM الحالية، ويبدو أن الخطوة رقم 2 في قسم المشغلات غير صحيحة.

بدلاً من مشغل عرض الصفحة (Page View)، يجب أن يكون هذا مشغل حدث مخصص (Custom Event) بالاسم virtualPageView.

يبدو أن cookieDomain = auto هو بقايا من Universal Analytics وغير ضروري. يتعامل GA4 تلقائيًا مع التنقل بين النطاقات الفرعية.

ممارسة أخرى جيدة هي تشغيل علامة Google (Google Tag) عند التهيئة (Initialization)، مع تعيين send_page_view إلى false وبدلاً من ذلك وجود علامة حدث GA4 منفصلة لـ page_view.

عندما قمنا بالتنفيذ، أضفنا أيضًا تجاوزًا لـ page_location مع عنوان URL الكامل للموقع + مسار الصفحة الافتراضية. سيؤدي هذا إلى ملء تقارير GA4 القياسية بشكل صحيح.

إعجاب واحد (1)

مرحباً ستيفان،

شكراً لك على هذه الملاحظات.

لقد قمت بتحديث الخطوة رقم 2 في قسم المشغلات (Triggers) حيث كان لدي بالفعل لقطات شاشة مطابقة، وسنقوم بتحديث بقية هذا في أقرب وقت ممكن.

إعجابَين (2)

الوصف:

أواجه مشكلة مع مدير علامات جوجل (GTM) على منتدى Discourse الخاص بي. دعني أشرح إعداداتي والمشكلة بالتفصيل:

  1. إعداد GTM:

    • لقد قمت بإعداد حاوية مدير علامات جوجل (المعرف: GTM-…MZV).
    • لأغراض الاختبار، أضفت علامة Google Analytics 4 في GTM، وتم تكوينها للتشغيل على جميع الصفحات أثناء التهيئة.
    • لم أضف أي مشغلات معقدة، أو طبقة مستخدم، أو طبقة بيانات. إنها مجرد تهيئة أساسية للتحقق من أن GTM يعمل.
  2. تكامل GTM مع Discourse:

    • في منتدى Discourse الخاص بي، قمت بتهيئة GTM عن طريق إدخال معرف الحاوية (GTM-W…MZV) في إعدادات المسؤول.
    • عند فحص موقعي، يمكنني رؤية أن:
  3. المشكلة:

    • بعد نشر حاوية GTM الخاصة بي، ذهبت إلى وضع المعاينة في مدير علامات جوجل وأدخلت عنوان URL الخاص بموقعي (https://forum.hobiguru.com).
    • ومع ذلك، يقول مصحح أخطاء معاينة GTM أنه لم يتم العثور على علامة GTM على موقعي.
    • على الرغم من تحميل gtm.js وعدم وجود أخطاء مرئية، فإن مصحح الأخطاء لا يتعرف على إعداد GTM.

لقطات شاشة:

  • لقطة الشاشة 1: إعداد حاوية GTM في مدير علامات جوجل (تظهر علامة GA4 والمشغلات).
  • لقطة الشاشة 2: إعدادات مسؤول Discourse تظهر معرف حاوية GTM (GTM-W…MZV) الذي تم تكوينه.
  • لقطة الشاشة 3: أدوات مطوري المتصفح تظهر أن مكتبة gtm.js تم تحميلها بنجاح على موقعي.
  • لقطة الشاشة 4: وضع معاينة GTM يظهر رسالة الخطأ: لم يتم العثور على علامة GTM على موقعك.



ما جربته حتى الآن:

  • تأكدت من تحميل gtm.js في علامة Network.
  • تحققت من وحدة تحكم المتصفح بحثًا عن أي سياسة أمان المحتوى (CSP) أو أخطاء JavaScript أخرى.
  • مسحت ذاكرة التخزين المؤقت على موقعي والمتصفح للتأكد من عدم وجود مشكلة في التخزين المؤقت.
  • أعدت نشر حاوية GTM للتأكد من تحديثها.

طلب:

هل يمكن لأحد مساعدتي في فهم سبب عدم اكتشاف وضع معاينة GTM لإعداد GTM الخاص بي، على الرغم من تحميل نص gtm.js البرمجي بشكل صحيح؟ هل هناك شيء فاتني في عملية الإعداد أو التكامل؟