> For the complete documentation index, see [llms.txt](https://docs.line.openad.network/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.line.openad.network/getting-started/for-publisher/how-to-integrate-apps-on-more-platforms/native-js-app.md).

# Native JS APP

This document provides instructions on how to access the SDK in native HTML (Games, etc.).

***

## Step #1. Load SDK

#### #1. Load the SDK in the body of html, the code is as follows:

```html
<body>
  <!--Your codes above-->
  <script
      name="openADJsSDK"
      version="3.0"  
      type="text/javascript" 
      src="https://protocol.openad.network/sdkloader.js">
  </script>
</body>
```

We recommend to add your application version number or release timestamp after JS to obtain the latest JS SDK for your application. E.g.,

> <https://protocol.openad.network/sdkloader.js?t=your-app-release-timestamp>

> <https://protocol.openad.network/sdkloader.js?v=your-app-version>

The script will pick OpenAD node for your end users, and load proper version of OpenAD SDK for you.

#### #2. Add DOM placeholder for Ad banner

```html
<body>
  <!-- code before banner -->
  <div class="openADJsSDKBanner #your_style_class" 
       publisherld="49"
       zoneld="158">
  </div>
  <!-- code after banner -->
</body>
```

> zoneld="158", 158 is a demo zoneld, please use your own "zoneId". publisherld="49", 49 is a demo publisherld, please use your own "publisherld" feel free to define your own banner style

OpenAD SDK will get ad banner for your end users and has it rendered in the DOM placeholder.

In traditional web applications, you can see OpenAD banner been rendered.

## Step #2. Get Ad Info

Please embed the following code into the body.

```js
<script type="text/javascript">
    window.addEventListener('DOMContentLoaded',  function() {
        window.openAdNative = {
            adInfo: {
               zoneId: 158, // please check your parameter zoneId
               publisherId: 49, // please check your parameter publisherId
               eventId: 0, // Reserved Parameter
            },
            adParams: {
                version: 'your-app-version', // optional
                TG: true, // optional, should be set if the application is TMA
            },
            // userInfo object
            // please add reasonable user IDs for your end users.
            // otherwise, OpenAD statistics may be inaccurate,
            // which may affect your incentives
            userInfo： {
                userId    : '', // user ID , If there is no data, please leave it blank
                firstName : '', // firstName or userId , If there is no data, please leave it blank
                lastName  : '', // lastName or userId , If there is no data, please leave it blank
                username  : '', // userName or userId , If there is no data, please leave it blank
            },
            // If the user is already logged in, initialize user data
            initUserInfo: function(data){
                this.userInfo.userId = data.userId;
                this.userInfo.firstName = data.firstName;
                this.userInfo.lastName = data.lastName;
                this.userInfo.username = data.username;
            },
            // Call SDK method to get advertising data
            getAD: function(){
                window.openADJsSDK.bridge.init({ userInfo: this.userInfo, adParams: this.adParams, adInfo: this.adInfo });
            },
            // Close AD
            destroy: function(adInfo){
              document.querySelector(`.openADJsSDKBanner[zoneId="${adInfo.zoneId}"][publisherId="${adInfo.publisherId}"]`).innerHTML = '';
            }
        };
    });
</script>
```

#### `Event Callback`

If the user is already logged in,

1. Initialize user data (optional, not need to set in TMA)

> window\.openAdNative.initUserInfo(data);

2. Get Ad Info

> window\.openAdNative.getAD();

3. Close AD

> window\.openAdNative.destroy(window\.openAdNative.adInfo);


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.line.openad.network/getting-started/for-publisher/how-to-integrate-apps-on-more-platforms/native-js-app.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
