इसके लिए, अनुमति लेना ज़रूरी है
GTM नियम बनाता है. इसे अभी आज़माएं या उदाहरण देखें.
अनुरोध
एचटीटीपी अनुरोध
POST https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers/containerId/rules
पैरामीटर
पैरामीटर का नाम | वैल्यू | ब्यौरा |
---|---|---|
पाथ पैरामीटर | ||
accountId |
string |
GTM खाता आईडी. |
containerId |
string |
GTM कंटेनर आईडी. |
अनुमति देना
इस अनुरोध के लिए नीचे दिए गए दायरे के साथ अनुमति की ज़रूरत है (पुष्टि करने और अनुमति देने के बारे में ज़्यादा पढ़ें).
स्कोप |
---|
https://www.googleapis.com/auth/tagmanager.edit.containers |
अनुरोध का मुख्य भाग
अनुरोध के मुख्य हिस्से में, नीचे दी गई प्रॉपर्टी के साथ नियम से जुड़ा संसाधन दें:
प्रॉपर्टी का नाम | वैल्यू | ब्यौरा | ज़रूरी जानकारी |
---|---|---|---|
ज़रूरी प्रॉपर्टी | |||
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')
इसे आज़माएं!
इस तरीके को लाइव डेटा पर कॉल करने और रिस्पॉन्स देखने के लिए, नीचे दिए गए एपीआई एक्सप्लोरर का इस्तेमाल करें.