Apps Network
  • 1. Introduction to Apps Network
  • 2. Getting Started
    • Quick Start Guide
  • 3. For Publishers
  • 4. For Advertisers
    • 4.1 API Reference - Click Verification
    • 4.2 API Reference - Reporting Challenge Completion
  • 5. Points System
  • 6. Banner Types and Placements
  • 7. Analytics and Reporting
  • 8. Solution Architecture
    • 8.1 System Components Overview
    • 8.2 Core Functionality and Workflows
    • 8.3 Technical Implementation Details
    • 8.4 System Diagram
  • 9. Frequently Asked Questions (FAQs)
  • 10. Glossary of Terms
  • 11. Release Notes
    • MVP1 Release Notes
    • MVP2 Release Notes
    • MVP3 Release Notes
Powered by GitBook
On this page
  • Creating Offer Wall
  • Implementing Offer Wall Code
  • For React JS Applications
  • Checking User Challenges and Rewarding Users
  • Sample code snippet
  • Implementing custom offer wall
  • Earning Apps Network Points

3. For Publishers

Publishers in the Apps Network system earn points by offering tasks and challenges in their games or web apps.

Creating Offer Wall

To start displaying tasks and challenges and earn points, create an offer wall:

  1. Log into your Apps Network account.

  2. Click on "Offerwall" in the top navigation menu.

  3. On the Offer Wall page, view your current offer wall.

  4. Click the "Create Offerwall" button to add a new one.

Specify the following details:

  • Type: Offerwall (by default)

  • Description: Brief inventory description

  • Reward Title: Reward title will be shown the action button next to each tasks item of the Offerwall, e.g.Play for +10 score. It’s a statement to your users for completing tasks and challenges in Apps Network.

Implementing Offer Wall Code

After creating your offer wall:

  1. Click "Snippets" in the main menu and check out the frontend framework your app uses.

  2. Add this code to your HTML <head>:

<script src="https://bec.apps-network.net/latest/bec.js?walletAddress=YOUR_WALLET_ADDRESS"></script>

The YOUR_WALLET_ADDRESS is automatically populated with your TON wallet address (hashed for security).

  1. Add the offer wall object initialization:

<button id="openOfferWallButton">Open Offer Wall</button>

<script>
document.addEventListener('DOMContentLoaded', function() {
  const openOfferWallButton = document.getElementById('openOfferWallButton');
  openOfferWallButton.addEventListener('click', function() {
    if (TE && typeof TE.offerWall === 'function') {
      TE.offerWall();
    } else {
      console.error('TE is not defined or offerWall is not a function');
    }
  });
});
</script>

For React JS Applications

Load the BEC script after DOM render:

useEffect(() => {
  const script = document.createElement('script');
  script.src = "https://bec.apps-network.net/latest/bec.js?walletAddress=YOUR_WALLET_ADDRESS";
  script.async = true;
  document.body.appendChild(script);
  return () => {
    document.body.removeChild(script);
  };
}, []);

Use BEC in React components:

const LandingPage = () => {
  useEffect(() => {
    // Load BEC script here (as shown above)
  }, []);

  return (
    <div className="min-h-screen flex flex-col">
      <div id="exchangeBanner"></div>
      <button onClick={() => {
        if (TE && typeof TE.offerWall === 'function') {
          TE.offerWall();
        }
      }}>Open Offer Wall</button>
    </div>
  );
};

Checking User Challenges and Rewarding Users

Publishers must reward users for completing the tasks from the offer wall. Check completed tasks and challenges or the offer wall clicks and reward your users:

  1. Use the Apps Network public API endpoint:

GET https://click.apps-network.net/banners/events?wa=YOUR_WALLET_ADDRESS&tui=TELEGRAM_USER_ID
  1. Parse the response to identify completed challenges and clicks made by the user Telegram ID tui. The response will look like this:

{
  "items": [
    {
      "click_id": "unique_click_identifier",
      "action": "CLICK",
      "tui": "telegram_user_id",
      "time": 1234567890,
      "ads_id": "ad_identifier"
    },
    {
      "click_id": "another_unique_identifier",
      "action": "PLAY",
      "tui": "telegram_user_id",
      "time": 1234567891,
      "ads_id": "ad_identifier"
    }
  ]
}
  1. Distribute in-game rewards based on the events in the response:

    • For publishers: Reward users based on the number of events (e.g., 100 points per event).

    • For advertisers: Verify clicks and award initial points (e.g., 100 points for a verified click).

  2. Consider your Apps Network user role (publisher or advertiser) when implementing the reward logic in your game.

Sample code snippet

The following code snippet demonstrates how to implement a reward system in a Telegram Mini App (TMA) that interacts with the Apps Network API to fetch user events and distribute rewards based on those events.

// Assuming this function is part of your game's logic
async function checkAndRewardUser(walletAddress) {
  const telegramUserId = getTelegramUserId(); // Implement this function to get the user's Telegram ID
  const apiUrl = `https://click.bec.apps-network.net/banners/events?wa=${encodeURIComponent(walletAddress)}&tui=${telegramUserId}`;

  try {
    const response = await fetch(apiUrl);
    if (!response.ok) {
      throw new Error('Failed to fetch events');
    }

    const data = await response.json();
    console.log('Events data:', data);

    if (data.items && data.items.length > 0) {
      // Calculate reward based on the number of events
      const rewardPoints = data.items.length * 100;

      // Check if there's at least one click event
      const hasClickEvent = data.items.some(item => item.action === "CLICK");

      if (hasClickEvent) {
        console.log(`Rewarding user with ${rewardPoints} points for ${data.items.length} events`);
        await updateUserScore(rewardPoints); // Implement this function to update the user's score in your game
        showRewardNotification(rewardPoints); // Implement this function to show a reward notification to the user
      } else {
        console.log('No click events found, no reward given');
      }
    } else {
      console.log('No events found, no reward given');
    }
  } catch (error) {
    console.error('Error checking and rewarding user:', error);
  }
}

// Example usage
document.getElementById('checkRewardButton').addEventListener('click', checkAndRewardUser);

// Helper functions (implement these according to your game's logic)
function getTelegramUserId() {
  // In a real TMA, you would get this from the Telegram WebApp
  return window.Telegram.WebApp.initDataUnsafe.user.id;
}

async function updateUserScore(points) {
  // Implement your logic to update the user's score in your game
  console.log(`Updating user score by ${points} points`);
  // Example: currentScore += points;
}

function showRewardNotification(points) {
  // Implement your logic to show a reward notification to the user
  console.log(`Showing reward notification: You earned ${points} points!`);
  // Example: alert(`Congratulations! You earned ${points} points!`);
}

Implementing custom offer wall

Publishers that implement custom offer wall may need access to functions for accessing thr SDK API directly including the initialization time. For the custom offer wall rendering the TE.offerWall() should not be called but instead loadTasks() and get the JSON to render the items in your own way. The fetchTasks() is called if the offer wall is scrolled and needs more items to display.

if (TE && typeof TE.loadTasks === 'function') {
    let result = await TE.loadTasks();
    let taskList = document.getElementById('taskList');
    taskList.innerHTML = JSON.stringify(result);
}

Earning Apps Network Points

Earn points to spend in Apps Network when visitors click tasks or complete challenges. Track your earnings as a publisher in the Profile page.

Use earned points to promote your own project across the App Network.

PreviousQuick Start GuideNext4. For Advertisers

Last updated 3 months ago

Check this for a demo and see its source page.

link