Expressions and Functions are helpful tools to create template variables or generate custom content in keyword fields, URL fields, sitelink fields, text ad fields, and others.
Special Characters
Example: Special Symbols versus Static Text when using the CAPITALIZE function.
Functions
Most functions have the format NAME(argument1;argument2;…), where arguments are separated by a semicolon.
Use-cases for Google’s ad customizers:
- Temporary promotions
- Ad testing
- Include prices, stock levels or discounts in an ad dynamically
More information and examples:
- An expression specifying how to transform the third and following arguments (may be empty).
- A condition they must fulfill after having been transformed (may be empty).
- A series of expressions to transform (applying argument 1) and then test (applying argument 2); the first transformed expression that passes the test will be returned; if none passes the test, NULL will be returned.
Within the transformation and test arguments (#1 and #2), the wildcard * will be replaced with the expressions to actually use (#3 and above).
- If argument 1 is empty, the expressions will be used as is instead of being transformed.
- If argument 2 is empty, the first expression that is not NULL will be returned.
Example:
FALLBACKS(UPPERCASE(*);MAXLENGTH(*;4);Not Lars;A long text with more than 4 characters;Lars)
LARS
Example: For the exact keyword “shoes”, the function generates the hash for “shoes exact”.
The LPAD function consists of three arguments. Imagine having IDs with a different number of digits, e.g. IDs ranging from 1 to 1000. In order to easily perform an analysis in Excel, it is useful for all IDs to have the same length, in this case 4 digits.
In the first argument, put the text or number you wish to edit. In the second argument, put a number indicating the desired number of digits/characters. In the third argument, put the digits/characters to fill in when the first argument has less characters/digits than specified in the second argument. When the length of the ID/text exceeds what is specified in the second argument, it’s cut to the specified number.
Example:
IF(MAXLENGTH(This is a text;10);short;long) text
long text
Hint: MAXLENGTH can be used when a keyword should be relying on a table column that sometimes has empty fields. If keywords should only get generated when a table entry exists, use this function. It checks if the shortname column is empty. Only if it is not empty, is the keyword is created.
Example:
FALLBACKS(;MAXBYTELENGTH(*;4);hello;hey;good morning) has 4 bytes
hey has 4 bytes
Example:
MD5(test)
098f6bcd4621d373cade4e832627b4f6
Example:
NORMALIZEWHITESPACE(Hello world !!!)
Hello world !!!
Example:
This function will perform a wildcard search for the string “something” in the url parameter table column. For each field containing the string “something” or strings that contain the pattern “something” (for example: “abcsomethingdef”), the function will be “true”, otherwise it will be “false”.
Example:
Hello REGEXREPLACE(worl ;\s+;d)
Hello world
Example:
REPLACE(old;new;That looks like something really old.)
That looks like something really new.
Example:
REPLACEALL({“ä”:”ae”,”ö”:”oe”,”ü”:”ue”,”Ä”:”Ae”,”Ö”:”Oe”,”Ü”:”Ue”,”ß”:”ss”};Öhne Ümläutchen wäre die Wült ärmer. Äber wer braucht schön daß scharfe ß?)
Oehne Uemlaeutchen waere die Wuelt aermer. Aeber wer braucht schoen dass scharfe ss?
Example:
Der {#ctb01_02#} wird SMARTREPLACE({#ctb01_02#};{#ctb02_02#};Chris,) der {#ctb01_01#} wird noch viel SMARTREPLACE({#ctb01_01#};_UPPERCASE({#ctb02_01#}er); {#ctb01_01#}), selbst der Döner wird SMARTREPLACE(D;sch;Döner!)
Der Chris wird lieb, der Lars wird noch viel TOLLER, selbst der Döner wird schöner!
Example:
TIMEOFFSET(-100), TIMEOFFSET(250)
1338998824, 1338999174
Example:
TRIM( whatever )
whatever
Example:
TRUNCATE(Hello world!!!;11)
Hello world
Example:
TODAY()
120606
Example:
UNIXTIMESTAMP()
1338998924
Example:
UPPERCASE(hello)
HELLO
Example:
http://www.example.com/URLENCODE(buy it now, save $$)
http://www.example.com/buy+it+now%2C+save+%24%24
Example:
http://www.project-a.com/URLENCODE2(buy it now, save $$)
http://www.project-a.com/buy%20it%20now%2C%20save%20%24%24
Operators
Operators return a boolean value (true or false).
Example:
IF(name@cat=shoes;equal;unequal)! with name@cat being shoes
equal!
Example:
IF(name@cat!=socks;unequal;equal)! with name@cat being shoes
unequal!
Example:
n=4, m=2; IF(n > m ;n;m)!
n!
Example:
n=2, m=2; IF(n >= m ;n;m)!
n!
Example:
n=2, m=4; IF(n < m ;n;m)!
n!
Example:
n=4, m=4; IF(n <= m;n;m)!
n!
Advanced Hints
Nesting of functions enables to build complex dependencies including multiple arguments and different functions.