Вопрос

I have code from my ad network that I am trying insert into an existing rule to call an ad from the server and place it into a div.

The javascript code is given to me to, normally, to embed in my header:

<script type="text/javascript">var z=document.createElement("script");z.type="text/javascript";z.async=true;z.src="http://engine.adzerk.net/z/12735/azk1_2_5";var s = document.getElementsByTagName("script")[0];s.parentNode.insertBefore(z, s);</script> 

And then the div portion that is placed in the body:

<div id="azk1"></div>

The div is being placed like with this:

rule NAME {
    select when pageview "url"
    pre {
        ad = '<div id="azk1"></div>';
    }
    replace_inner("#ad-slot-1", ad);

}

First, is the div placement done correctly? and second, how do I need to format the javascript for the rule? Do I use a global emit? can I store it on another server and call it? If so, how should that be formatted?

Thx

Это было полезно?

Решение

You can do it two ways. The first is the use resource syntax. Put this in the global block:

use javascript resource "http://yourserver.com/path/to/javascript.js"

Then put the JavaScript like normal in that file.

The second option is to use an emit in the rule itself. It goes in the action block, so your new rule would look like this:

rule NAME {
    select when pageview "url"
    pre {
        ad = '<div id="azk1"></div>';
    }
    {
        emit <|
            // Your JavaScript here
        |>;
        replace_inner("#ad-slot-1", ad);
    }
}

The JavaScript you would put in the file or in that emit block is everything between the <script> tags in the code you originally gave.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top