Skip to content

What is a macro?#

A macro is a piece of JavaScript that controls the browser with built-in functions: click, type, scroll the page, read elements, solve captchas... For code that has to run inside the web page itself (for example reading document.title), put it in the EvalScript function.

Where macros run#

Macros run in three places, with the same set of functions:

  • 9Hits campaigns: run in 9Hits Viewer on every view of your page, to add actions instead of just opening the page and waiting.
  • 9Login scripts: run in 9Login profiles.
  • Studio: where you write and test macros.

File and process functions do not run in 9Hits campaigns!

Where to write and test macros#

Write and test in Studio first, then paste the macro into the Macros tab of the campaign form. This tab has two boxes: Main macro runs in the window that opens the campaign URL, and Popup macro runs in every popup that opens after that. The two scripts do not share variables. See the Macros tab.

For 9Login, you can create scripts in its management section and save the code you wrote in Studio there to use with your profiles.

TheCampaign: info about the running campaign#

Macros in 9Hits campaigns have a built-in variable TheCampaign that holds id, url and duration (the view duration, in seconds). Use duration to split the view time into several steps:

// TheCampaign looks like { id: 123, url: "https://example.com", duration: 30 }
await ScrollTo(0, 800, true);                 // first half: scroll the page
await Delay(TheCampaign.duration * 1000 / 2); // wait half the duration (milliseconds)
await ClickRandomInternalLink();              // second half: interact