-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.tpl
245 lines (221 loc) · 7.4 KB
/
template.tpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
___TERMS_OF_SERVICE___
By creating or modifying this file you agree to Google Tag Manager's Community
Template Gallery Developer Terms of Service available at
https://developers.google.com/tag-manager/gallery-tos (or such other URL as
Google may provide), as modified from time to time.
___INFO___
{
"type": "MACRO",
"id": "cvt_temp_public_id",
"version": 1,
"securityGroups": [],
"displayName": "Split String",
"description": "Split string with any delimeter. Return only split value, everything after the split, or limited string returned.",
"categories": [
"UTILITY",
"TAG_MANAGEMENT",
"ANALYTICS"
],
"containerContexts": [
"SERVER"
]
}
___TEMPLATE_PARAMETERS___
[
{
"type": "TEXT",
"name": "input",
"displayName": "Input",
"simpleValueType": true,
"valueValidators": [
{
"type": "NON_EMPTY"
}
],
"alwaysInSummary": true,
"canBeEmptyString": false,
"help": "Input Variable that you want to split."
},
{
"type": "TEXT",
"name": "delimiter",
"displayName": "Delimiter",
"simpleValueType": true,
"valueValidators": [
{
"type": "NON_EMPTY"
}
],
"alwaysInSummary": true,
"help": "Enter \u003cstrong\u003edelimiter\u003c/strong\u003e for splitting the string, eg. \u003cstrong\u003e/\u003c/strong\u003e if you are splitting a Page Path.\n\u003cbr /\u003e\u003cbr /\u003e\nTo split based on \u003cstrong\u003espaces\u003c/strong\u003e in the string, type \u003cstrong\u003espace\u003c/strong\u003e as delimiter.\n\u003cbr /\u003e\u003cbr /\u003e\n\u003cstrong\u003eRegular Expression\u003c/strong\u003e split is \u003cstrong\u003enot\u003c/strong\u003e supported.",
"valueHint": "/"
},
{
"type": "GROUP",
"name": "returnGroup",
"groupStyle": "NO_ZIPPY",
"subParams": [
{
"type": "SELECT",
"name": "returnValue",
"displayName": "Select Occurence to Return",
"selectItems": [
{
"value": "first",
"displayValue": "First Occurrence"
},
{
"value": "last",
"displayValue": "Last Occurrence"
},
{
"value": "nthStart",
"displayValue": "Nth Occurrence from Start of string"
},
{
"value": "nthEnd",
"displayValue": "Nth Occurence from End of string"
}
],
"simpleValueType": true,
"alwaysInSummary": true
},
{
"type": "TEXT",
"name": "nthValue",
"displayName": "Nth Occurrence",
"simpleValueType": true,
"valueValidators": [
{
"type": "POSITIVE_NUMBER"
}
],
"enablingConditions": [
{
"paramName": "returnValue",
"paramValue": "nthStart",
"type": "EQUALS"
},
{
"paramName": "returnValue",
"paramValue": "nthEnd",
"type": "EQUALS"
}
],
"help": "Enter the ocurrence number where you want the split to happen. \n\u003cbr /\u003e\u003cbr /\u003e\nIf you have selected \u003cstrong\u003eNth Occurence from Start of string\u003c/strong\u003e, the first occurence is \u003cstrong\u003e0\u003c/strong\u003e.\n\u003cbr /\u003e\u003cbr /\u003e\nIf you have selected \u003cstrong\u003eNth Occurence from End of string\u003c/strong\u003e, the first occurence is \u003cstrong\u003e1\u003c/strong\u003e.",
"valueHint": "1"
},
{
"type": "GROUP",
"name": "returnGroupEnhanced",
"displayName": "Enhanced Split Result",
"groupStyle": "NO_ZIPPY",
"subParams": [
{
"type": "CHECKBOX",
"name": "returnAllAfterSplit",
"checkboxText": "Return Complete String after Split",
"simpleValueType": true,
"help": "If selected, the complete string after the split will be returned. \u003cbr /\u003e\u003cbr /\u003e\nE.g. if your string is \u003cstrong\u003ethe-quick-brown-fox-jumps-over-the-lazy-dog\u003c/strong\u003e, and you split using \u003cstrong\u003e-\u003c/strong\u003e (hyphen) at occurence \u003cstrong\u003e2\u003c/strong\u003e, the value returned is \u003cstrong\u003ebrown-fox-jumps-over-the-lazy-dog\u003c/strong\u003e.",
"alwaysInSummary": true,
"enablingConditions": [
{
"paramName": "returnValue",
"paramValue": "last",
"type": "NOT_EQUALS"
}
]
},
{
"type": "CHECKBOX",
"name": "limitReturnValues",
"checkboxText": "Limit Complete String Returned",
"simpleValueType": true,
"enablingConditions": [
{
"paramName": "returnAllAfterSplit",
"paramValue": true,
"type": "EQUALS"
}
],
"help": "If selected, the complete string after the split will be limited. \u003cbr /\u003e\u003cbr /\u003e E.g. if your string is \u003cstrong\u003ethe-quick-brown-fox-jumps-over-the-lazy-dog\u003c/strong\u003e, and you split using \u003cstrong\u003e-\u003c/strong\u003e (hyphen) at occurence \u003cstrong\u003e2\u003c/strong\u003e, and the limitation number is set to \u003cstrong\u003e3\u003c/strong\u003e, the value returned is \u003cstrong\u003ebrown-fox-jumps\u003c/strong\u003e."
},
{
"type": "TEXT",
"name": "limitReturn",
"simpleValueType": true,
"valueHint": "2",
"valueValidators": [
{
"type": "POSITIVE_NUMBER"
}
],
"enablingConditions": [
{
"paramName": "limitReturnValues",
"paramValue": true,
"type": "EQUALS"
}
],
"alwaysInSummary": true
}
]
}
]
}
]
___SANDBOXED_JS_FOR_SERVER___
const makeString = require('makeString');
const makeNumber = require('makeNumber');
const log = require('logToConsole');
const input = makeString(data.input);
const delimiter = data.delimiter === 'space' ? ' ' : data.delimiter;
const parts = input.split(delimiter);
let index;
switch(data.returnValue) {
case 'first':
index = 0;
break;
case 'last':
index = parts.length-1;
break;
case 'nthStart':
index = data.nthValue;
break;
case 'nthEnd':
index = parts.length-data.nthValue;
break;
}
const limit = data.limitReturn ? (makeNumber(index)+makeNumber(data.limitReturn)) : parts.length;
const result = data.returnAllAfterSplit ? parts.slice(index,limit).join(delimiter): parts[index];
if(result) {
return result;
}
___SERVER_PERMISSIONS___
[
{
"instance": {
"key": {
"publicId": "logging",
"versionId": "1"
},
"param": [
{
"key": "environments",
"value": {
"type": 1,
"string": "debug"
}
}
]
},
"clientAnnotations": {
"isEditedByUser": true
},
"isRequired": true
}
]
___TESTS___
scenarios: []
___NOTES___
Created on 2/22/2022, 9:15:48 PM