Skip to content

Store API Integration

serdarakay edited this page Jun 20, 2025 · 1 revision

🧩 Using GameDistribution Store API in Cocos Creator

You can integrate the GameDistribution Store API in your Cocos Creator HTML5 projects using JavaScript. This enables access to virtual items, currencies, cart actions, and inventory features provided by the GameDistribution Store system.


βœ… 1. Set Up Your Project

Make sure your Cocos Creator project is exported as an HTML5 Web project. Then include the GameDistribution SDK in your HTML template.

In your index.html or template:

<script type="text/javascript">
  window["GD_OPTIONS"] = {
    gameId: "your-game-id",
    onEvent: function(event) {
      console.log("GD Event:", event);
    }
  };
</script>
<script src="https://html5.api.gamedistribution.com/main.js"></script>

✍️ 2. Use Store API in Your Code

You can call Store API methods from your game's script files.

Example: Fetch Store Items

const items = await gdsdk.executeStoreAction({ action: "api.items" });
console.log("Available store items:", items);

Example: Buy Product

await gdsdk.executeStoreAction({
  action: "api.buyProduct",
  payload: { sku: "ss-enhance-shield-5", quantity: 1 }
});

πŸ“Š 3. UI Integration Tips

You can call UI-related store actions like:

Open Store UI

gdsdk.executeStoreAction({ action: "ui.open" });

Close Store UI

gdsdk.executeStoreAction({ action: "ui.close" });

These can be triggered from in-game buttons, events, or lifecycle hooks.


πŸ”— Example Screenshots (coming soon)

Please check back for screenshot references for integrating buttons or calling actions from components in Cocos Creator Editor.


πŸ“– Related Docs

πŸ”— GameDistribution HTML5 SDK - Store API Usage

If you need an example project for Cocos, please contact the GameDistribution developer team.