נדרשת הרשאה
יצירת כלל GTM. אפשר לנסות עכשיו או לראות דוגמה.
בקשה
בקשת HTTP
POST https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers/containerId/rules
פרמטרים
שם הפרמטר | Value | התיאור |
---|---|---|
פרמטרים של נתיב | ||
accountId |
string |
מספר החשבון ב-GTM. |
containerId |
string |
מזהה מאגר התגים של GTM. |
הרשאות
בקשה זו מחייבת הרשאה בהיקף הבא (למידע נוסף על אימות והרשאה).
היקף |
---|
https://www.googleapis.com/auth/tagmanager.edit.containers |
גוף הבקשה
בגוף הבקשה, מספקים משאב כללים עם המאפיינים הבאים:
שם הנכס | Value | התיאור | הערות |
---|---|---|---|
מאפיינים נדרשים | |||
condition[].parameter[] |
list |
רשימה של פרמטרים בעלי שם (מפתח/ערך), בהתאם לסוג התנאי. הערות:
|
ניתן לכתיבה |
condition[].parameter[].type |
string |
סוג הפרמטר. הערכים החוקיים הם:
הערכים הקבילים הם:
|
ניתן לכתיבה |
condition[].type |
string |
סוג האופרטור של התנאי הזה.
הערכים הקבילים הם:
|
ניתן לכתיבה |
name |
string |
השם המוצג של הכלל. | ניתן לכתיבה |
מאפיינים אופציונליים | |||
condition[] |
list |
רשימת התנאים שמרכיבים את הכלל הזה (משתמע AND) ביניהם). | ניתן לכתיבה |
condition[].parameter[].key |
string |
המפתח בעל השם שמזהה פרמטר באופן ייחודי. נדרש לפרמטרים ברמה העליונה, וגם לערכי מפה. המערכת התעלמה מערכים ברשימה. | ניתן לכתיבה |
condition[].parameter[].list[] |
list |
הפרמטרים של פרמטר הרשימה הזו (המערכת תתעלם מהמפתחות). | ניתן לכתיבה |
condition[].parameter[].map[] |
list |
הפרמטרים של פרמטר המפה הזה (חייבים לכלול מפתחות, המפתחות חייבים להיות ייחודיים). | ניתן לכתיבה |
condition[].parameter[].value |
string |
ערך של פרמטר (עשוי להכיל הפניות מאקרו כגון "") בהתאם לסוג שצוין. | ניתן לכתיבה |
notes |
string |
המשתמש מציין איך להחיל את הכלל הזה בכלי הקיבול. | ניתן לכתיבה |
תשובה
אם הפעולה בוצעה ללא שגיאות, השיטה הזו תחזיר משאב הכללים בגוף התגובה.
דוגמאות
הערה: דוגמאות הקוד הזמינות לשיטה זו לא מייצגות את כל שפות התכנות הנתמכות (רשימת השפות הנתמכות זמינה בדף של ספריות המשתמשים).
Java
משתמש בספריית הלקוח של Java.
/* * Note: This code assumes you have an authorized tagmanager service object. */ /* * This request creates a new rule for the authorized user. */ // Construct the condition parameters. Parameter arg0 = new Parameter(); arg0.setType("template"); arg0.setKey("arg0"); arg0.setValue("{{url}}"); Parameter arg1 = new Parameter(); arg1.setType("template"); arg1.setKey("arg1"); arg1.setValue(".*hellowworld.html"); // Construct the condition object Condition condition = new Condition(); condition.setType("endsWith"); condition.setParameter(Arrays.asList(arg0, arg1)); // Construct the rule object. Rule rule = new Rule(); rule.setName("Ends With Rule"); rule.setCondition(Arrays.asList(condition)); try { Rule response = tagmanager.accounts(). containers().rules().create("123456", "54321", rule).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("Rule Id = " + response.getRuleId()); System.out.println("Rule Fingerprint = " + response.getFingerprint());
Python
עושה שימוש בספריית הלקוח של Python.
# Note: This code assumes you have an authorized tagmanager service object. # This request creates a new rule for the authorized user. try: response = tagmanager.accounts().containers().rules().create( accountId='123456', containerId='54321', body={ 'name': 'Ends with Rule', 'condition': [ { 'type': 'endsWith', 'parameter': [ { 'type': 'template', 'key': 'arg0', 'value': '{{url}}' }, { 'type': 'template', 'key': 'arg1', 'value': '.*hellowworld.html' } ] } ] } ).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 'Rule Id = %s' % response.get('ruleId') print 'Rule Fingerprint = %s' % response.get('fingerprint')
רוצה לנסות?
ניתן להשתמש ב-APIs Explorer שבהמשך כדי לקרוא לשיטה הזו בנתונים בזמן אמת ולראות את התגובה.