> For the complete documentation index, see [llms.txt](https://docs.responsiveads.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.responsiveads.com/developers/code-examples/passing-custom-macros-to-creative-javascript.md).

# Passing Custom Macros to Creative JavaScript

{% embed url="<https://www.loom.com/share/ead83a20121843d096df2832492e8b34>" %}

Use this setup when a ResponsiveAds creative needs to receive dynamic values from the ad server, such as campaign ID, placement ID, site ID, page category, audience segment, or other custom data.

### How It Works

Custom values are passed into the creative through the ad tag configuration.

In production, these values should be assigned to ad server macros. When the ad is served, the ad server replaces the macros with real values. The creative can then read those values through custom JavaScript and use them for logic, tracking, or personalization.

### Setup

First, identify which values the creative needs from the ad server.

Next, add those values as custom options in the ad-tag configuration. Each option should use the correct macro syntax for the ad server where the tag will be trafficked.

<figure><img src="/files/GsI7jF2u9nzgwwPB6507" alt=""><figcaption></figcaption></figure>

After that, deploy the ad tag through the ad server. The ad server will resolve the macros at runtime and pass the final values into the creative.

Inside the creative, use custom JavaScript to read the ad-tag options and apply the values where needed.

### Getting the Value in Custom JavaScript

Inside the creative, the value can be accessed from the AdStack options using the `red.getAdStackOptions()` method.

Use the same option name that was added to the AdStack configuration. For example, if the AdStack option is named `placementId`, the creative JavaScript should read that same `placementId` value from the AdStack options.

Once the value is available in custom JavaScript, it can be used to control creative behavior, update messaging, pass information into tracking, or trigger custom logic.

There is currently no UI-based workflow for using these values directly in the creative. Any behavior based on the passed value needs to be handled through custom JavaScript.

```javascript
//How to use custom JS
//https://docs.responsiveads.com/developers
var rad = Radical.getAdByWindow(window);
var container = rad.getContainer();
var inScreenshot = window.location.href.indexOf('preview?screenshot=1') > -1 ? true : false;

//get the tag parameter Value
//#####################################################
var tagParamValue = rad.getAdTagOptions().tagParamName;
//#####################################################

console.log(tagParamValue);

if (!rad.getMergedContent().inEditor) { 
	rad.onLoad(onAdLoaded);
	rad.onRender(onAdRender);
	rad.onBeforeRender(onBeforeRender);
}
function onAdRender() {
	var background = rad.getElementById('e2');
}

//{ elementDefs:elementDefs, elementStyles:elementStyles }
function onBeforeRender(arg) {
	//arg.elementStyles['e2'].visible = false;
}

function onAdLoaded() {

}
```

### Common Uses

Custom macro values can be used to:

* Change creative behavior by placement or campaign.
* Personalize messaging based on page or audience data.
* Pass metadata into tracking or analytics.
* Trigger different creative logic for different environments.

### Troubleshooting

If the value is missing, check that the option was added to the ad-tag correctly.

If the creative receives the raw macro instead of the final value, the ad server is not replacing it. Check the macro syntax and whether that macro is supported in the trafficked field.

If the creative behavior is incorrect, confirm that the received value matches the expected format, including spelling and capitalization.

### Summary

Pass ad server macros into the ad-tag configuration, let the ad server resolve them at runtime, and use custom JavaScript in the creative to read and apply the resulting values.
