Macros allow to dynamically insert strings in URL, for example, keywords, source and subId.

Built-in macros:

  • {keyword} - current keyword;
  • {keyword_cp1251} - keyword in encoding windows-1251;
  • {ip} - IP address;
  • {group_key} - a group alias;
  • {group_id} - a group number;
  • {stream_id} - a stream number;
  • {referrer} - referrer;
  • {country_code} - a country code ISO-3166-1;
  • {city} — a city;
  • {se_referrer} — referrer from the search engine;
  • {date:format} — the date in the specific format (More about formats;
  • {subid} — unique SubID of the visitor;
  • {source} — traffic source;
  • {from_file:filename.txt} — inserts the contents of the file filename.txt from directory /var/macros/;
  • {se}
  • {device_type}
  • {device_model}

All values are encoded through urlencode() by default. If you want to insert the original value, add the underscore symbol—{_macro}.

Here are some examples of using macros:


The Macros of GET-parameters

All parameters which were sent to TDS, are wrapped into macro with the same name. For example, if you pass http://tds/group?utm_source=google then paste{utm_source} in the stream.

Creating Macros

All macro scripts are located in directory /application/macros/. There are also located built-in macros, you can see their code.

Create a new macro that will return a random number.

1. Create a file in /application/macros/random.php

2. The code:

class random_macros extends AbstractMacros
    public function process(Stream $stream, Visitor $visitor, $min, $max)
        return rand($min, $max);

The class name random_macros is made up of the macro name “random” and the word “_macros”. The class must contain a method “process” and at least two variables of the method: $stream, $visitor.

3. After creating the macro you can use it in URLs, for example,{random:100,999}

random — the macro name 100, 999 — the first and second arguments, values $min, $max.

Read about $stream and $visitor object $stream, object $visitor