Templating Information on scripts and templates. Adhese does not restrict advertising to the use of IAB Standard Formats only. The Adhese Templates solution allows you to wrap more complex creatives such as overlayers, takeovers or floor ads by adding advanced functionality using JavaScript, HTML and CSS. Advar Templates Adhese has introduced a new template format called Advar . Advar templates are pre-defined creatives to create sophisticated ads consisting of Javascript, CSS, custom JSON objects etc. The results of Advar templates are pre-made ads, such as a text ad including a small image. Advar templates can have multiple components (images, videos, texts and URLs) that form the final creative. The user provides these elements (or parameters) when they create a new Advar ad. The user responsible for adding a new creative to a campaign does not require coding knowledge in HTML, CSS or JavaScript. The template predefines the code and presents it as a form to the user. See Add an Advar creative . An Advar template always consists of two files: The creative's actual content contains parameters that refer to the properties of an uploaded creative and its files. Besides any custom parameter defined by the creator of the Advar template, the creative content can also contain several fixed parameters. A descriptive file generates the form that the user will see and use when uploading an Advar creative. The file contains a JSON object that defines the different elements available in the template. It will determine how to render the form to the user. As with templates, an Advar template can also contain a request element as a parameter. An Advar template can use all request properties as content. For example, the creative can display the visitor's name if the call to the ad server contains this parameter (and if the value of the name is available, of course). The Advar templates screen lists the name of the Advar template in the Format column . Create a new Advar template To create a new Advar template: Go to the Administration screen. Click Admin in the left navigation menu. Click Advar templates . The Advar templates screen opens: Click Create an Advar template . The Create a new Advar template screen opens: Enter a name in the Name field. Choose a clear and logical name, such as pp-textad.txt . Insert the code in the File contents field. This code represents the actual content of the creative and includes parameters that refer to the properties of the uploaded creative and its files. Refer to the Appendix Parameters for templates and Advar templates for an overview of the available parameters. Here is an example of some pieces of code:

Add inline style attributes to an element to specify the design of the ad. The Example for creating new ads from this template field contains the descriptive file and makes it possible to create input fields when using an Advar template file to upload an ad. These input fields become visible when you select an Advar template as a creative. The descriptive file contains a JSON object that defines the different elements available in the template. It will determine how to render the form to the user. It can contain three types of fields: singleLineText, multilineText, and select (i.e. a list of options). Below is an example of the corresponding description file for the above Advar template, followed by a screenshot of the Advar form in the Adhese interface: { "files": [{ "default": "", "doc": "This will be used as logo", "label": "A first image", "key": "2nd" },{ "default": "", "doc": "This will be used as background", "label": "A second image", "key": "3rd" }], "advar": "advar_example.txt", "fields": [{ "default": "", "doc": "Select the source of your article", "label": "Article source", "type": "select", "key": "", "options": [{ "value": "afp", "label": "AFP" },{ "value": "belga", "label": "Belga" },{ "value": "reuters", "label": "Reuters" }] },{ "default": "", "doc": "Fill in the title of your article", "label": "Title", "type": "singleLineText", "key": "" },{ "default": "", "doc": "Fill in the text of your article", "label": "Text", "type": "multilineText", "key": "" } ]} Click the Save button. Edit an Advar template To edit an Advar template: Go to the Administration screen. Click Admin in the left navigation menu. Click Advar templates . In the list of Advar templates, click the Advar template you want to modify. The Edit template screen opens: Change any of the Advar template's details. Click Save . HTML5 Templates It is not possible to use Adhese macros such as [adheseReplace:xx] or from within an HTML5 template. Unlike regular (advar) templates, these macros will not work. An HTML5 template is a combination of a regular advar template and a folder with HTML, CSS and JS files. It allows you to use the form functionality of an advar template while storing code and optional media in a folder structure. In  Admin > Formats and templates > HTML5 templates, you can find all previously created templates in zip format. When you click on the link, the following screen will appear: The following options are available: Upload a new file: click the Upload a new HTML5 template file (ZIP) and choose a file to upload. Delete a template: select the file and click the delete button . Filter the list by typing in the filter box. Using HTML5 templates Previously created HTML5 templates can be used by clicking the ' Add advar' option in the creative tab and selecting the correct template in the ' Add Advar Template' dropdown list. Creating a new HTML5 template Ensure that the filenames only contain alphanumeric characters, dots, and underscores. Other characters may cause issues when Adhese processes the file! Steps for creating and uploading a new template: Locally, create a new folder in which to store all files Choose a name for the template: [name].zip Create a descr.json file and store it in the main directory of your folder. The content has to be constructed in the same way you would create a regular advar template. (See step 6 of creating a new advar ) Create an index.html file - which will be the starting point for the HTML5 ad - and store it in the main directory of your folder Make sure to incorporate clickthrough logic . Adhese relies on it to track clicks correctly. You can do this by adding the following line of code to your index.html file. Adhese will add its click tracking URL to this variable, after which you can use it in the rest of your clickthrough logic. Optionally you can store CSS, JS and images in separate files & folders within the main directory. All links in the HTML5 creative, such as the link to an image within the ad, need to use a relative path, for example: /graphics/ad-image.png or . This enables the ad to be self-contained and, therefore, to run independently or to render without a network connection. External libraries and web fonts can be an exception to this guideline.   Zip the content of the folder (not the folder itself) and change the name of the zip to the name of the template Upload the template in the Adhese UI under Admin > Formats and templates > HTML5 templates, Test the template by creating a creative and checking the preview of the banner Troubleshooting HTML5 Templates If an HTML5 template can't be uploaded for some reason, you'll get an error message: In the case above, hidden files might block Adhese from properly unzipping the archive: When creating an archive on Mac OS, a hidden __MACOSX folder might be created. These files must be removed for the upload to succeed (you may need to unzip, delete and re-zip the files). In the case above, the zip file has been renamed. If the zip file does not match the advar name in the descr.json file, rename the zip file to match the advar name in the descr.json file, and the archive can be uploaded. Template Repository The Template Repository lets you control Template files and Advar templates using a Git version control system. Once this option is enabled, you can store your templates in your own version control system maintain a detailed history of your changes effortlessly switch between different versions of your templates edit templates in your preferred IDE check out a specific branch in your Adhese account. Changes in the checked-out version on your Adhese account will be applied to all relevant creatives and will be pushed online with the next publish. Directory Structure The main directory of your repository can be used to store all 'regular' templates. In most implementations these are no longer used and can therefor be ignored. More relevant are the advar templates and the 'HTML5' advar templates. Both types will be stored in separate folders: " advar_templates " and " html5_templates ". Advar templates More info about advar templates can be found here Each advar template consists of 2 files: The file that contains the actual response template. This file can be made out of HTML, JSON or XML code. It will depend on the type of integration the template will be used for. The extension can be .txt or something that matches the content of the template. A description file that contains the form used to create an advar creative. This file will contain specific JSON markup. More info on this can be found  here . The file needs to have the same name as the first file, followed by the extension .descr .  HTML5 templates More info about HTML5 templates can be found here HTML5 templates are stored as compressed folders using the .zip extension. Each HTML5 template has their own HTML, CSS and JS structure within that folder and need to have a description file named descr.json in the main directory.  Usage The Template Repository screen shows two panels. On the left, you can see a summary of the Git commits currently used. It contains the Git hash, the branch, and the date and message when it was committed. On the right, you see a text field and button to change the commit for checkout: Enter branch name or Git hash to use (e.g. origin/master) Press Checkout button The specified Git commit will be checked out. All the template changes will be applied in the next publish phase. Activation To activate this option, please get in touch with our Support department. You will also need to provide the following information: the URL of your Git repository, this needs to be accessible from the outside (e.g. git@github.com :adhese/my_template_repo.git) We will send you the public SSH key that you need to add to your Git configuration to allow us access to the repository you would like to use for managing your templates. If you use GitHub, add this as an SSH key to Your Repo > Settings > Deploy Keys. Adhese Parameters Server-side request parameters The ad server replaces the following list of parameters with the request information for each personalised request. The parameters can be included in any template, including Advar templates or third-party code. Parameter Description [adheseExpand: ] [adheseReplace: ] Is replaced by the values sent with the corresponding ID from the request. [adheseLogID] A unique number used for reporting. [adheseRequestData] All parameters used in the ad request. [adheseRequestDataFlat] Contains the full request as it is sent to the ad server but replaces all semicolon-separated values by a /prefixValue/ clause. [adheseSetExpandPrefix: ] [adheseTimestampNowMs] Unix timestamp at the moment of sending the response, the number of milliseconds since 1970-01-01 0:00:00. [adheseAdditionalRequestParameters:] This parameter can contain additional parameters that are added to the targets of the request, for example, dmADV ;OR . [adheseEnv:] This parameter is replaced by the environment variable of the request, for example [adheseEnv:HTTP_HOST]. See [http://en.wikipedia.org/wiki/Common_Gateway_Interface](http://en.wikipedia.org/wiki/Common_Gateway_Interface) for an overview of all environment variables. [adheseReplace:SL] The value of the string identification for the requested position. [adheseReplace:A2] The value of the identification cookie. [adheseDomain:ad_host], [adheseDomain:click_host], [adheseDomain:pool_host], [adheseDomain:track_host] Contains the incoming host for the request. Usefull for 1st domain implementations with multiple domains. Parameters for templates and Advar templates When working with advar templates & advar creatives, you need to use the 2ND (and higher)  macro's when adding macro's related to uploaded creative files.  Examples are , Parameter URIENCODED Description The comment of the booking.   The end date of a booking.   The unique ID of the booking. The external reference or key of a booking.   The start date of a booking.   The ID of the selected Advertiser company The content of the alt text field. The body of the creative (if available). The click tag of a creative (including URL). If configured, the tracking URL that has been configured in the configuration.   The unique ID of the link between the booking and the creative. The name of the creative. The delivery multiples value of the booking. The group ID for the delivery multiples, if needed. , , , , ,   The duration of the uploaded video files in seconds. , , , , , The duration of the uploaded video files in milliseconds. , , , , , , , , , , The file extension of each uploaded file. The content of the extra field 1. The content of the extra field 2. The format of the booking. ,   The dimensions of the third file that is uploaded. ,   The dimensions of the fourth file that is uploaded. ,   The dimensions of the fifth file that is uploaded. ,   The dimensions of the sixth file that is uploaded.   The unique ID of a creative in Adhese. This ID can be used to make JavaScript functions unique.     The name of the campaign.   The location of where the ad is located on the server. The position of the booking. The priority of the campaign. Deprecated. , , , , , , , , , , The target URLs of the uploaded files, will be empty in case not uploaded. The complete HTML code of an ad: object/embed code in case of a .swf file, JavaScript in case of third-party code, or img link tags in case of a static image. The code of the template for the position of the booking. The export code of the template of the creative. The URL for tracking 3rd party impressions. The target URL or landing page of the ad, as determined by the user. The URL to count trackable impressions The URL to count viewable impressions. ,   The dimensions of the first uploaded file. ,   The dimensions of the second file that is uploaded. Stack sequence Sequencing The sequence parameter can be used in advar templates to sort ads within the request response, and is therefore only relevant for stack implementations where multiple ads are returned for one placement.  Some examples are: VAST Adpods  Digital Out Of Home playlists Native advertising Sequence suggestions are optional, and when implemented, Adhese will do its best to place the ad in the desired position within the response. You can enter any number as a sequence suggestion, but obviously, it only makes sense to use unique numbers. An option is to use Adhese macros such as to implement sorting based on the creative ID. The sequence value is stripped from the response when the adpod or stack response is rendered. Templates VAST If sequence=0 , the ad is preferred to be placed first in a pod. If sequence=-1 , the ad prefers to be placed last in a pod. If  sequence=1 it prefers the second place and so on. This ordering happens after the ads are selected, so there is no guarantee that an ad with sequence=0 will always be first in the pod (unless if it is the highest priority of all possible options). VAST ad implementation JSON The sequence field must be added to the main structure of the JSON template. The order logic will not work if the field is added inside a nested object in the JSON structure. { "sequence": 0, "example field": "some value" } Runtime time string replacement and encoding Adhese contains a number of scripts that can be added to any kind of template and will be interpreted at runtime. This allows you to create complex templates where variables can be transformed or encoded via the adheseScript tags. The scripts are useful for URL encoding, JavaScript escaping, string replacement and other similar tasks. Tags in the format [adheseScript...] have a corresponding [/adheseScript] . Each tag applies some modifications to the text in between these tags. Note that it is possible to nest these tags to apply multiple operations to the same text. The tags are then applied one at a time, with the inner ones being applied first and then the outer ones. Example of nested tags: [adheseScriptBase64Decode] [adheseScriptReplace:-:l]he--o wor-d[/adheseScript] [/adheseScript] Let's look at some tags in more detail. Non-escaping script tags adheseScriptReplace Searches the enclosed input text for the first parameter and replaces it with the second parameter. Search and replace is done with literal text, not with regex. [adheseScriptReplace:-:l]he--o wor-d[/adheseScript] This results in hello world adheseScriptLower Puts the enclosed input text in lowercase. [adheseScriptLower]FOOBAR[/adheseScript] results in foobar adheseScriptBase64Decode Applies Base64 decoding to the enclosed input text. [adheseScriptBase64Decode]What a nice string of characters[/adheseScript] results in V2hhdCBhIG5pY2Ugc3RyaW5nIG9mIGNoYXJhY3RlcnM= adheseScriptUriEncode Applies UriEncoding to the enclosed input text. [adheseScriptUriEncode]What a nice string of characters[/adheseScript] results in What%20a%20nice%20string%20of%20characters Escaping script tags By default, some escaping is applied to any [adhese...] tags. If multiple tags are nested inside each other, the default escaping will only be applied once, after the final tag is executed. The default escaping does the following: ' → \' " → \" \ → \\ ]]> → ]]]]> \b \t \n \r \f unicode characters outside the range 32, 0x7f This should be sufficient for the majority of use cases. However, there may be edge cases where additional control over escaping is required. This can be achieved by utilising one of the tags outlined below. For example: When used within XML without CDATA tags (although we recommend the use of CDATA tags instead of more complex escaping techniques) When multiple payloads are nested within each other, a single round of escaping is not enough. The default escaping process would protect against the injection of malicious code into the JavaScript, but an attacker would be able to inject malicious code into the inner HTML. To ensure security, this tag must be escaped twice. var foo = ""; When [adhese...] tags are placed directly inside HTML without being enclosed in ' or " By default < and > are not escaped, so an attacker could insert any HTML they want.

[adhese...]

If the outermost tags apply to escape (as in one of the tags listed below, except for adheseScriptEscape), then the default escaping is disabled. If JSON is requested, additional JSON escaping will be applied. This additional escaping is the same as the default escaping described above, with the exception of single quotes and ]]> , which are not escaped. Additional escaping is applied even when the default escaping is turned off. adheseScriptEscapeXMLCDATA ]]> → ]]]]> Useful in XML CDATA tags when the default escaping breaks things by escaping too much. adheseScriptEscapeXML Useful for escaping inside XML that does not use CDATA tags. See https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/StringEscapeUtils.html#escapeXml11(java.lang.String) for details. adheseScriptEscapeJSStringWFS Equivalent to the default escaper but doesn't escape ]]> Useful for js. Doesn't escape / so don't use it directly in a js regex replace adheseScriptEscapeJSString Equivalent to adheseScriptEscapeJSStringWFS but it also escapes / see also: https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/StringEscapeUtils.html#escapeEcmaScript(java.lang.String) adheseScriptEscapeHTML applies https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/StringEscapeUtils.html#escapeHtml4(java.lang.String) but also escapes ' → ' adheseScriptEscapeNone Escapes nothing, which is useful for JSON fields that are not embedded into something else (as the separate JSON escaping is enough there).