خدمة "إدارة العلامات من Google"

توفر خدمة "إدارة العلامات من Google" إمكانية الوصول إلى بيانات واجهة برمجة تطبيقات إدارة العلامات من Google لمستخدم مفوّض. تتيح هذه الخدمة لمستخدمي أداة "إدارة العلامات من Google" إدارة الحسابات وcontainers والبيئات وversions ومساحات العمل والمجلدات والمتغيّرات والعوامل المُشغِّلة والعلامات والمستخدِمِين.

مَراجع

للاطّلاع على معلومات مفصّلة حول هذه الخدمة، راجِع المستندات المرجعية الإصدار 2 من Tag Manager API.

مثل جميع الخدمات المتقدمة في لغة "برمجة التطبيقات"، تستخدم خدمة "إدارة العلامات من Google" العناصر والطرق والمعلَمات نفسها مثل واجهة برمجة التطبيقات العامة. لمزيد من المعلومات، يُرجى الاطّلاع على كيفية تحديد توقيعات الطرق.

للإبلاغ عن المشاكل والعثور على وسائل دعم أخرى، يُرجى الاطّلاع على مركز مساعدة أداة "إدارة العلامات من Google".

نموذج التعليمات البرمجية

يوضّح نموذج الرمز التالي كيفية استخدام بعض ميزات خدمة "إدارة العلامات من Google".

تنشئ إصدارًا حاوية باستخدام متغير ومشغّل وعلامة.

يستخدِم الرمز النموذجي التالي الإصدار الثاني من واجهة برمجة تطبيقات "إدارة العلامات" لإنشاء حاوية أولاً باسم طابع زمنيّ بالتاريخ الحالي لتحسين فرص أن تكون فريدة. ينشئ النموذج بعد ذلك مساحة عمل بمتغير قيمة عشوائية، ومشغلًا يتم تنشيطه لأي مشاهدة صفحة. بعد ذلك، يستخدم النموذج المشغِّل لإنشاء علامة بكسل عشوائية من خلال تنشيط وحدة البكسل على //example.com مع إلحاق منظم ذاكرة التخزين المؤقت بنهاية عنوان URL. أخيرًا، تنشئ العينة إصدار حاوية باستخدام الكيانات المذكورة أعلاه، وتسجّل الإصدار وتعيده للاستخدام لاحقًا.

advanced/tagManager.gs
/**
 * Creates a container version for a particular account
 * with the input accountPath.
 * @param {string} accountPath The account path.
 * @return {string} The tag manager container version.
 */
function createContainerVersion(accountPath) {
  const date = new Date();
  // Creates a container in the account, using the current timestamp to make
  // sure the container is unique.
  try {
    const container = TagManager.Accounts.Containers.create(
        {
          'name': 'appscript tagmanager container ' + date.getTime(),
          'usageContext': ['WEB']
        },
        accountPath);
    const containerPath = container.path;
    // Creates a workspace in the container to track entity changes.
    const workspace = TagManager.Accounts.Containers.Workspaces.create(
        {'name': 'appscript workspace', 'description': 'appscript workspace'},
        containerPath);
    const workspacePath = workspace.path;
    // Creates a random value variable.
    const variable = TagManager.Accounts.Containers.Workspaces.Variables.create(
        {'name': 'apps script variable', 'type': 'r'},
        workspacePath);
    // Creates a trigger that fires on any page view.
    const trigger = TagManager.Accounts.Containers.Workspaces.Triggers.create(
        {'name': 'apps script trigger', 'type': 'PAGEVIEW'},
        workspacePath);
    // Creates a arbitary pixel that fires the tag on all page views.
    const tag = TagManager.Accounts.Containers.Workspaces.Tags.create(
        {
          'name': 'apps script tag',
          'type': 'img',
          'liveOnly': false,
          'parameter': [
            {'type': 'boolean', 'key': 'useCacheBuster', 'value': 'true'}, {
              'type': 'template',
              'key': 'cacheBusterQueryParam',
              'value': 'gtmcb'
            },
            {'type': 'template', 'key': 'url', 'value': '//example.com'}
          ],
          'firingTriggerId': [trigger.triggerId]
        },
        workspacePath);
    // Creates a container version with the variabe, trigger, and tag.
    const version = TagManager.Accounts.Containers.Workspaces
        .create_version(
            {'name': 'apps script version'}, workspacePath)
        .containerVersion;
    console.log(version);
    return version;
  } catch (e) {
    // TODO (Developer) - Handle exception
    console.log('Failed with error: %s', e.error);
  }
}

تنشر إصدار حاوية ويقدِّم معاينة سريعة لمسودة الحاوية الحالية.

يستخدِم نموذج الرمز البرمجي التالي الإصدار 2 من واجهة برمجة تطبيقات "إدارة العلامات من Google" لقبول إصدار حاوية قد يكون قد تمّ إنشاؤه في المثال أعلاه، واسترداد الحساب والحاوية وأرقام تعريف الإصدارات من الإصدار. ويستخدم النموذج هذه المعرّفات لنشر إصدار حاوية على مستوى العالم بشكل مباشر. أخيرًا، ينشئ النموذج معاينة سريعة لمساحة عمل جديدة ويسجّل المعاينة السريعة.

advanced/tagManager.gs
/**
 * Retrieves the container path from a container version path.
 * @param  {string} versionPath The version path.
 * @return {string}             The container path.
 */
function grabContainerPath(versionPath) {
  const pathParts = versionPath.split('/');
  return pathParts.slice(0, 4).join('/');
}

/**
 * Publishes a container version publically to the world and creates a quick
 * preview of the current container draft.
 * @param {object} version The container version.
 */
function publishVersionAndQuickPreviewDraft(version) {
  try {
    const containerPath = grabContainerPath(version.path);
    // Publish the input container version.
    TagManager.Accounts.Containers.Versions.publish(version.path);
    const workspace = TagManager.Accounts.Containers.Workspaces.create(
        {'name': 'appscript workspace', 'description': 'appscript workspace'},
        containerPath);
    const workspaceId = workspace.path;
    // Quick previews the current container draft.
    const quickPreview = TagManager.Accounts.Containers.Workspaces
        .quick_preview(workspace.path);
    console.log(quickPreview);
  } catch (e) {
    // TODO (Developer) - Handle exceptions
    console.log('Failed with error: $s', e.error);
  }
}

إنشاء بيئة مستخدم وإعادة تفويضها.

يستخدِم نموذج الرمز البرمجي التالي الإصدار الثاني من واجهة برمجة تطبيقات "إدارة العلامات من Google" لقبول إصدار الحاوية واستخراج الحساب والحاوية وأرقام تعريف الإصدارات. يستخدِم النموذج أرقام التعريف هذه لإنشاء بيئة مستخدِم تشير إلى إصدار حاوية الإدخال وتسجّل بيئة المستخدِم. ينتهي النموذج بتسجيل بيئة مستخدم تمت إعادة تفويضها.

advanced/tagManager.gs
/**
 * Retrieves the container path from a container version path.
 * @param  {string} versionPath The version path.
 * @return {string}             The container path.
 */
function grabContainerPath(versionPath) {
  const pathParts = versionPath.split('/');
  return pathParts.slice(0, 4).join('/');
}

/**
 * Creates and reauthorizes a user environment in a container that points
 * to a container version passed in as an argument.
 * @param {object} version The container version object.
 */
function createAndReauthorizeUserEnvironment(version) {
  try {
    // Creates a container version.
    const containerPath = grabContainerPath(version.path);
    // Creates a user environment that points to a container version.
    const environment = TagManager.Accounts.Containers.Environments.create(
        {
          'name': 'test_environment',
          'type': 'user',
          'containerVersionId': version.containerVersionId
        },
        containerPath);
    console.log('Original user environment: ' + environment);
    // Reauthorizes the user environment that points to a container version.
    TagManager.Accounts.Containers.Environments.reauthorize(
        {}, environment.path);
    console.log('Reauthorized user environment: ' + environment);
  } catch (e) {
    // TODO (Developer) - Handle exceptions
    console.log('Failed with error: $s', e.error);
  }
}

يُسجِّل جميع أذونات الوصول إلى الحاويات والرسائل الإلكترونية ضمن أحد الحسابات.

يستخدِم نموذج الرمز البرمجي التالي الإصدار الثاني من واجهة برمجة تطبيقات "إدارة العلامات" للعثور على قائمة بجميع الأذونات ضمن حساب أداة "إدارة العلامات من Google". بعد ذلك، يسجِّل النموذج عنوان البريد الإلكتروني للمستخدم ومعرّف الحاوية وأنواع أذونات الوصول إلى الحاوية لكل إدخال.

advanced/tagManager.gs
/**
 * Logs all emails and container access permission within an account.
 * @param {string} accountPath The account path.
 */
function logAllAccountUserPermissionsWithContainerAccess(accountPath) {
  try {
    const userPermissions =
      TagManager.Accounts.User_permissions.list(accountPath).userPermission;
    for (let i = 0; i < userPermissions.length; i++) {
      const userPermission = userPermissions[i];
      if ('emailAddress' in userPermission) {
        const containerAccesses = userPermission.containerAccess;
        for (let j = 0; j < containerAccesses.length; j++) {
          const containerAccess = containerAccesses[j];
          console.log(
              'emailAddress:' + userPermission.emailAddress +
            ' containerId:' + containerAccess.containerId +
            ' containerAccess:' + containerAccess.permission);
        }
      }
    }
  } catch (e) {
    // TODO (Developer) - Handle exceptions
    console.log('Failed with error: $s', e.error);
  }
}