कस्टम वैरिएबल बनाएं
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
इस गाइड में, कस्टम वैरिएबल टेंप्लेट बनाने का तरीका बताया गया है. टास्क कब शुरू होगा
इस वैरिएबल का इस्तेमाल किया जाता है, तो यह वैल्यू की श्रेणी लेगा और उन्हें
कॉमा डिलिमिटेड स्ट्रिंग.
अपना पहला वैरिएबल टेंप्लेट शुरू करने के लिए, बाईं ओर मौजूद टेंप्लेट पर क्लिक करें
वैरिएबल टेंप्लेट में जाकर, नया बटन पर क्लिक करें
सेक्शन में जाएं.
जानकारी टैब में, वैरिएबल का नाम और ब्यौरा तय करें.
जब लोग इस नाम को लागू करेंगे, तब उन्हें नाम दिया जाएगा
टैग मैनेजर के यूज़र इंटरफ़ेस में वैरिएबल का इस्तेमाल किया जा सकता है.
ब्यौरा वैसा ही है जैसा यह सुनने में लगता है - छोटा (200 वर्ण या
कम) ब्यौरा दें.
अपने टेंप्लेट की झलक देखने के लिए, रीफ़्रेश करें पर क्लिक करें.
फ़ील्ड इनपुट की दाईं ओर, टेंप्लेट की झलक विंडो होती है.
एडिटर में हर बार कोई बदलाव करने पर, रीफ़्रेश करें बटन
दिखाना चाहते हैं. 'रीफ़्रेश करें' पर क्लिक करके देखें कि आपके बदलावों से आपकी
वैरिएबल.
अपने वैरिएबल टेंप्लेट में फ़ील्ड जोड़ने के लिए, फ़ील्ड पर क्लिक करें.
टेम्प्लेट संपादक के फ़ील्ड टैब से आप
वैरिएबल टेंप्लेट. फ़ील्ड का इस्तेमाल कस्टम डेटा डालने के लिए किया जाता है, जैसे कि खाता
आईडी. ड्रॉप-डाउन मेन्यू में जाकर, टेक्स्ट फ़ील्ड जैसे स्टैंडर्ड फ़ॉर्म एलिमेंट जोड़े जा सकते हैं
मेन्यू, रेडियो बटन, और चेकबॉक्स चुने जा सकते हैं.
फ़ील्ड जोड़ें पर क्लिक करें और सिंपल टेबल चुनें. डिफ़ॉल्ट नाम बदलें (उदाहरण
"simpleTable1") "list" के साथ कॉन्फ़िगर की गई हो. टेंप्लेट की झलक में, रीफ़्रेश करें पर क्लिक करें.
टेक्स्ट इनपुट के लिए यह तरीका दोहराएं और इसे "अरे", दो चेकबॉक्स नाम दें
इसे "use_array" कहा जाता है और "sort" के साथ-साथ एक टेक्स्ट इनपुट भी शामिल करें, जिसे "डीलिमिटर" कहते हैं.
"deeplink" के लिए, इसे "," का डिफ़ॉल्ट मान दें गियर आइकॉन पर क्लिक करके,
"डिफ़ॉल्ट वैल्यू" को टॉगल करके चालू करें. इसके बाद, नई डिफ़ॉल्ट वैल्यू डालें
इनपुट फ़ील्ड.
कोड टैब पर क्लिक करें और एडिटर में सैंडबॉक्स की गई JavaScript डालें:
var input = data.array;
if (!data.use_array) {
input = [];
for (var i = 0; i < data.list.length; i++) {
input.push(data.list[i].values);
}
}
if (data.sort) {
input.sort();
}
return input.join(data.delimiter || ',');
इस वैरिएबल का कोड काफ़ी आसान है, लेकिन ऐसे कुछ कोड हैं
कुछ भी नहीं बताना चाहिए.
data
फ़ील्ड.
ऐसे कुछ फ़ील्ड हैं जिन्हें data
ग्लोबल के बाहर से ऐक्सेस किया जा रहा है.
data
में वे वैल्यू शामिल होंगी जिन्हें आपने पिछले चरण में सेट अप किया था.
इसलिए हम data.use_array
, data.sort
,
data.list
और data.delimiter
.
अगर data.delimiter
है, तो delimiter
को ","
की डिफ़ॉल्ट वैल्यू पर सेट किया जाता है
उपलब्ध नहीं कराया गया. किसी फ़ील्ड के लिए डिफ़ॉल्ट वैल्यू सेट करना एक अच्छा तरीका है, अगर
एक बात सही लगती है. इससे उपयोगकर्ताओं के लिए, वैरिएबल का इस्तेमाल करना आसान हो जाता है
टेंप्लेट का इस्तेमाल करने के लिए, क्योंकि उन्हें हर फ़ील्ड को भरने की ज़रूरत नहीं होती
वैरिएबल.
अपनी प्रगति सेव करने के लिए सेव करें पर क्लिक करें. ऐसा करने से, पहचानी गई सभी अनुमतियां लोड हो जाएंगी
टेम्प्लेट एडिटर में जाएगा.
कुछ टेंप्लेट एपीआई के पास उनसे जुड़ी अनुमतियां होती हैं. इनसे तय होता है कि क्या
या नहीं कर सकते हैं. जब sendPixel
जैसे टेंप्लेट एपीआई का इस्तेमाल किया जाता है
आपका कोड, Tag Manager, अनुमतियों में ज़रूरी अनुमतियां दिखाएगा
करें.
टेंप्लेट की झलक टैब में, "वैल्यू" के लिए कुछ वैल्यू जोड़ें इनपुट के लिए,
अपने वैरिएबल का आउटपुट देखने के लिए, कोड चलाएं और कंसोल पर जाएं.
अगर कोई गड़बड़ी होती है, तो वह कंसोल विंडो में दिखेगी.
सेव करें पर क्लिक करें और टेंप्लेट एडिटर बंद कर दें
वैरिएबल टेंप्लेट अब इस्तेमाल के लिए तैयार है.
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2025-07-25 (UTC) को अपडेट किया गया.
[null,null,["आखिरी बार 2025-07-25 (UTC) को अपडेट किया गया."],[[["\u003cp\u003eThis guide provides step-by-step instructions to create a custom variable template in Google Tag Manager.\u003c/p\u003e\n"],["\u003cp\u003eThis template transforms an array of values into a comma-separated string using JavaScript code within the template.\u003c/p\u003e\n"],["\u003cp\u003eThe template utilizes fields like 'list', 'array', 'use_array', 'sort', and 'delimiter' to customize its functionality.\u003c/p\u003e\n"],["\u003cp\u003eUsers can preview and test the template using the 'Template Preview' and 'Console' sections within the editor.\u003c/p\u003e\n"],["\u003cp\u003eOnce saved, the custom variable template is ready to be implemented within Google Tag Manager.\u003c/p\u003e\n"]]],["To create a variable template that returns a comma-delimited string from an array, start by creating a new template, defining its name and description in the *Info* tab. Then, in the *Fields* tab, add fields for a simple table (\"list\"), text input (\"array\"), checkboxes (\"use_array\", \"sort\"), and text input (\"delimiter\"). In the *Code* tab, enter sandboxed JavaScript to process these fields, joining the array with the specified delimiter, and save. Then preview the result and save the variable.\n"],null,["# Create a custom variable\n\nThis guide will walk you through how to create a custom variable template. When\nthis variable is used, it will take an array of values and return them as a\ncomma delimited string.\n\n1. To begin your first variable template, click Templates in the left\n navigation and click the *New* button under the *Variable Templates*\n section.\n\n2. In the *Info* tab, define the variable's *Name* and *Description*.\n\n **Name** is what will be presented to users when they go to implement this\n variable throughout the Tag Manager user interface.\n\n **Description** is just what it sounds like - a brief (200 characters or\n less) description of what this variable does.\n3. Click *Refresh* to preview your template.\n\n To the right of the field inputs, there is a *Template Preview* window.\n Every time a change is made in the editor, the **Refresh** button will\n appear. Click Refresh to see what your changes do to the appearance of your\n variable.\n4. Click *Fields* to add fields to your variable template.\n\n The Template Editor's **Fields** tab lets you create and edit fields in the\n variable template. Fields are used to enter custom data, such as an account\n ID. You can add the standard form elements like text fields, drop down\n menus, radio buttons, and checkboxes.\n5. Click *Add Field* and select *Simple table* . Replace the default name (e.g.\n *\"simpleTable1\"* ) with *\"list\"* . In the *Template Preview* , click *Refresh*.\n\n Repeat this step for a *Text Input* and call it *\"array\"* , two *Checkboxes*\n called \"*use_array* \" and *\"sort\"* , and a *Text Input* called *\"delimiter\"* .\n For *\"delimiter\"* , give it a default value of \",\" by clicking the gear icon,\n toggling *\"Default value\"* to on, and then filling in the new Default Value\n input field.\n6. Click the *Code* tab and enter sandboxed JavaScript in the editor:\n\n var input = data.array;\n\n if (!data.use_array) {\n input = [];\n for (var i = 0; i \u003c data.list.length; i++) {\n input.push(data.list[i].values);\n }\n }\n\n if (data.sort) {\n input.sort();\n }\n\n return input.join(data.delimiter || ',');\n\n The code for this variable is fairly straightforward, but there are a few\n things worth pointing out.\n - `data` fields.\n\n There are a few fields that are being accessed off of the `data` global.\n `data` will contain the values that you set up in the previous step.\n That's why we're able to access `data.use_array`, `data.sort`,\n `data.list`, and `data.delimiter`.\n - `delimiter` is set to a default value of `\",\"` if `data.delimiter` is\n not provided. It's a good practice to set default values for a field if\n one makes sense. This makes it easier for users to use the variable\n template, since they don't have to fill out every field in order to use\n the variable.\n\n7. Click *Save* to save your progress. This will load any detected permissions\n into the Template Editor.\n\n Some Template APIs have [permissions](/tag-platform/tag-manager/templates/permissions) associated with them that dictate what\n they can or cannot do. When you use a template API such as `sendPixel` in\n your code, Tag Manager will show relevant permissions in the **Permissions**\n tab.\n8. In the *Template Preview* tab, add some values for the \"values\" input, click\n **Run Code** , and look at the *Console* to see the output for your variable.\n\n If there are any errors, they will appear in the **Console** window.\n9. Click *Save*, and close the Template Editor\n\n The variable template should now be ready for use."]]