Macros: create

נדרשת הרשאה

יוצר מאקרו של GTM. אפשר לנסות עכשיו או לראות דוגמה.

בקשה

בקשת HTTP

POST https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers/containerId/macros

פרמטרים

שם הפרמטר Value התיאור
פרמטרים של נתיב
accountId string מספר החשבון ב-GTM.
containerId string מזהה מאגר התגים של GTM.

הרשאות

בקשה זו מחייבת הרשאה בהיקף הבא (למידע נוסף על אימות והרשאה).

היקף
https://www.googleapis.com/auth/tagmanager.edit.containers

גוף הבקשה

בגוף הבקשה, מספקים משאב מאקרו עם המאפיינים הבאים:

שם הנכס Value התיאור הערות
מאפיינים נדרשים
name string שם התצוגה של המאקרו. ניתן לכתיבה
parameter[].type string סוג הפרמטר. הערכים החוקיים הם:
  • boolean: הערך מייצג בוליאני, מיוצג כ-true או כ-false
  • integer: הערך מייצג ערך של מספר שלם חתום של 64 ביט, בבסיס 10
  • list: יש לציין רשימה של פרמטרים
  • map: יש לציין מפה של פרמטרים
  • template: הערך מייצג כל טקסט; הוא יכול לכלול הפניות מאקרו (גם הפניות מאקרו שעשויות להחזיר סוגים שאינם מחרוזות)


הערכים הקבילים הם:
  • "boolean"
  • "integer"
  • "list"
  • "map"
  • "template"
ניתן לכתיבה
type string סוג המאקרו GTM. ניתן לכתיבה
מאפיינים אופציונליים
disablingRuleId[] list עבור כלים מכילים של מכשירים ניידים בלבד: רשימה של מזהי כללים להשבתת פקודות מאקרו מותנות; המאקרו מופעל אם אחד מכללי ההפעלה מתקיים וכל כללי ההשבתה אינם נכונים. מטופל כקבוצה לא ממוינת. ניתן לכתיבה
enablingRuleId[] list עבור כלים מכילים של מכשירים ניידים בלבד: רשימה של מזהי כללים להפעלת פקודות מאקרו מותנות; המאקרו מופעל אם אחד מכללי ההפעלה מתקיים וכל כללי ההשבתה אינם נכונים. מטופל כקבוצה לא ממוינת. ניתן לכתיבה
notes string המשתמש הערות לגבי אופן ההחלה של מאקרו זה בכלי הקיבול. ניתן לכתיבה
parameter[] list הפרמטרים של רכיב המאקרו. ניתן לכתיבה
parameter[].key string המפתח בעל השם שמזהה פרמטר באופן ייחודי. נדרש לפרמטרים ברמה העליונה, וגם לערכי מפה. המערכת התעלמה מערכים ברשימה. ניתן לכתיבה
parameter[].list[] list הפרמטרים של פרמטר הרשימה הזו (המערכת תתעלם מהמפתחות). ניתן לכתיבה
parameter[].map[] list הפרמטרים של פרמטר המפה הזה (חייבים לכלול מפתחות, המפתחות חייבים להיות ייחודיים). ניתן לכתיבה
parameter[].value string ערך של פרמטר (עשוי להכיל הפניות מאקרו כגון "") בהתאם לסוג שצוין. ניתן לכתיבה
scheduleEndMs long חותמת הזמן של הסיום, באלפיות השנייה, לתזמון מאקרו. ניתן לכתיבה
scheduleStartMs long חותמת הזמן של ההתחלה באלפיות השנייה לתזמון מאקרו. ניתן לכתיבה

תשובה

אם הפעולה בוצעה ללא שגיאות, השיטה הזו תחזיר משאב מאקרו בגוף התגובה.

דוגמאות

הערה: דוגמאות הקוד הזמינות לשיטה זו לא מייצגות את כל שפות התכנות הנתמכות (רשימת השפות הנתמכות זמינה בדף של ספריות המשתמשים).

Java

משתמש בספריית הלקוח של Java.

/*
 * Note: This code assumes you have an authorized tagmanager service object.
 */

/*
 * This request creates a new macro for the authorized user.
 */

// Construct the macro object.
Macro macro = new Macro();
macro.setName("Sample URL Macro");
macro.setType("u");

// Construct the parameters.
Parameter arg0 = new Parameter();
arg0.setType("template");
arg0.setKey("component");
arg0.setValue("URL");

Parameter arg1 = new Parameter();
arg1.setType("template");
arg1.setKey("customUrlSource");
arg1.setValue("{{element}}");

// set the parameters on the macro.
macro.setParameter(Arrays.asList(arg0, arg1));

try {
  Macro response = tagmanager.accounts().
      containers().macros().create("123456", "54321", macro).execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}

/*
 * The results of the create method are stored in the response object.
 * The following code shows how to access the created Id and Fingerprint.
 */
System.out.println("Macro Id = " + response.getMacroId());
System.out.println("Macro Fingerprint = " + response.getFingerprint());

Python

עושה שימוש בספריית הלקוח של Python.

# Note: This code assumes you have an authorized tagmanager service object.

# This request creates a new macro for the authorized user.
try:
  response = tagmanager.accounts().containers().macros().create(
      accountId='123456',
      containerId='54321',
      body={
          'name': 'Sample URL Macro',
          'type': 'u',
          'parameter': [
              {
                  'type': 'template',
                  'key': 'component',
                  'value': 'URL'
              },
              {
                  'type': 'template',
                  'key': 'customUrlSource',
                  'value': '{{element}}'
              }
          ]
      }
  ).execute()

except TypeError, error:
  # Handle errors in constructing a query.
  print 'There was an error in constructing your query : %s' % error

except HttpError, error:
  # Handle API errors.
  print ('There was an API error : %s : %s' %
         (error.resp.status, error.resp.reason))

# The results of the create method are stored in the response object.
# The following code shows how to access the created id and fingerprint.
print 'Macro Id = %s' % response.get('macroId')
print 'Macro Fingerprint = %s' % response.get('fingerprint')

רוצה לנסות?

ניתן להשתמש ב-APIs Explorer שבהמשך כדי לקרוא לשיטה הזו בנתונים בזמן אמת ולראות את התגובה.