Yetkilendirme gerektirir
Bir GTM kuralı oluşturur. Hemen deneyin veya bir örneğe göz atın.
İstek
HTTP isteği
POST https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers/containerId/rules
Parametreler
Parametre adı | Değer | Açıklama |
---|---|---|
Yol parametreleri | ||
accountId |
string |
GTM Hesap Kimliği. |
containerId |
string |
GTM Kapsayıcı Kimliği. |
Yetkilendirme
Bu istek, aşağıdaki kapsamla yetkilendirme gerektirir (kimlik doğrulama ve yetkilendirme hakkında daha fazla bilgi edinin).
Kapsam |
---|
https://www.googleapis.com/auth/tagmanager.edit.containers |
İstek içeriği
İstek gövdesinde, aşağıdaki özelliklere sahip bir Kurallar kaynağı sağlayın:
Mülk adı | Değer | Açıklama | Notlar |
---|---|---|---|
Zorunlu mülkler | |||
condition[].parameter[] |
list |
Koşulun türüne bağlı olarak adlandırılmış parametrelerin (anahtar/değer) bir listesi. Notlar:
|
yazılabilir |
condition[].parameter[].type |
string |
Parametre türü. Geçerli değerler şunlardır:
Kabul edilebilir değerler şunlardır:
|
yazılabilir |
condition[].type |
string |
Bu koşul için operatör türü.
Kabul edilebilir değerler şunlardır:
|
yazılabilir |
name |
string |
Kuralın görünen adı. | yazılabilir |
İsteğe Bağlı Özellikler | |||
condition[] |
list |
Bu kuralı oluşturan koşulların listesi (aralarında örtülü VE). | yazılabilir |
condition[].parameter[].key |
string |
Bir parametreyi benzersiz şekilde tanımlayan adlandırılmış anahtar. Harita değerleri ve üst düzey parametreler için gereklidir. Liste değerleri için yoksayılır. | yazılabilir |
condition[].parameter[].list[] |
list |
Bu liste parametresinin parametreleri (anahtarlar yoksayılır). | yazılabilir |
condition[].parameter[].map[] |
list |
Bu eşleme parametresinin parametreleri (anahtar içermelidir, anahtarlar benzersiz olmalıdır). | yazılabilir |
condition[].parameter[].value |
string |
Bir parametrenin değeri (belirtilen türe uygun olduğu şekilde, "" gibi makro referansları içerebilir). | yazılabilir |
notes |
string |
Bu kuralın kapsayıcıya nasıl uygulanacağıyla ilgili kullanıcı notları. | yazılabilir |
Yanıt
Başarılı olursa bu yöntem, yanıt gövdesinde bir Kurallar kaynağı döndürür.
Örnekler
Not: Bu yöntem için kullanıma sunulan kod örnekleri, desteklenen tüm programlama dillerini kapsamaz (Desteklenen dillerin listesi için istemci kitaplıkları sayfasını inceleyin).
Java
Java istemci kitaplığı'nı kullanmalıdır.
/* * 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 istemci kitaplığı'nı kullanır.
# 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')
Deneyin.
Aşağıdaki API Gezgini'ni kullanarak canlı verilerde bu yöntemi çağırın ve yanıtı görün.