@adsgram/react 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,11 +15,11 @@ pnpm add @adsgram/react
15
15
  ## Components
16
16
 
17
17
  ### `<AdsgramTask />`
18
+ React wrapper component for the `<adsgram-task>` custom element. Using for the [Task](https://docs.adsgram.ai/publisher/task-examples) ad format.
18
19
 
19
- React component for the `<adsgram-task>` custom element.
20
+ <img src="https://docs.adsgram.ai/assets/native_task.Dp3rdtR0.png" alt="Task ad" width="300">
20
21
 
21
22
  #### Props
22
-
23
23
  | Prop | Type | Description |
24
24
  |--------------------|----------------|-----------------------------------------|
25
25
  | `blockId` | `string` | Unique task block ID (required) |
@@ -30,26 +30,30 @@ React component for the `<adsgram-task>` custom element.
30
30
  | `onBannerNotFound` | `EventHandler` | No banner available callback (optional) |
31
31
  | `onTooLongSession` | `EventHandler` | Long session callback (optional) |
32
32
 
33
- #### Example
33
+ #### Customization
34
+ More info about customization and slots usage see [here](https://docs.adsgram.ai/publisher/task-integration-example#_4-customise-task-so-it-fits-your-application-design)
34
35
 
36
+ #### Example
35
37
  ```tsx
38
+ import { JSX } from "react";
36
39
  import { AdsgramTask } from '@adsgram/react';
37
40
 
38
- const handleReward = () => {
39
- // your code to reward user
40
- };
41
41
 
42
- const handleError = () => {
43
- // do nothing or handle error
44
- };
42
+ export function Task(): JSX.Element | null {
43
+ const handleReward = (event: CustomEvent<string>): void => {
44
+ console.log("User earned reward:", event.detail);
45
+ };
46
+
47
+ const handleError = (event: CustomEvent<string>): void => {
48
+ console.error("Task error:", event.detail);
49
+ };
45
50
 
46
- function MyTask() {
47
51
  return (
48
52
  <AdsgramTask blockId="task-123" className={styles.task} onReward={handleReward} onError={handleError}>
49
53
  <span slot="reward" className={styles.task__reward}>1000 coins</span>
50
54
  <div slot="button" className={styles.task__button}>go</div>
51
- <div slot="claim" className={stylestask__button_claim}>claim</div>
52
- <div slot="done" className={stylestask__button_done}>done</div>
55
+ <div slot="claim" className={styles.task__button_claim}>claim</div>
56
+ <div slot="done" className={styles.task__button_done}>done</div>
53
57
  </AdsgramTask>
54
58
  );
55
59
  }
@@ -58,9 +62,11 @@ function MyTask() {
58
62
  ### Hook
59
63
 
60
64
  ### `useAdsgram`
65
+ React hook for managing fullscreen ads. Using for the [Reward](https://docs.adsgram.ai/publisher/reward-examples) and [Interstitial](https://docs.adsgram.ai/publisher/interstitial-examples) ad formats.
61
66
 
62
- #### Props
67
+ <img src="https://docs.adsgram.ai/assets/rewarded_video.CdG2Ubqt.png" alt="Fullscreen ad" width="300">
63
68
 
69
+ #### Props
64
70
  | Prop | Type | Description |
65
71
  | ------------------ | ------------------------------ | ------------------------------------------------- |
66
72
  | `blockId` | `string` | Unique ad block ID (required) |
@@ -77,22 +83,22 @@ An object with methods to control the Adsgram ad:
77
83
  - `destroy(): void` — Destroys the ad controller.
78
84
 
79
85
  #### Example
80
-
81
86
  ```tsx
87
+ import { JSX } from "react";
82
88
  import { useAdsgram } from '@adsgram/react';
83
89
 
84
- function MyAdButton() {
85
- const handleReward = () => {
90
+ export function AdButton(): JSX.Element {
91
+ const handleReward = (): void => {
86
92
  // user watch ad till the end
87
93
  // your code to reward user for rewarded format
88
94
  }
89
95
 
90
- const handleError = () => {
96
+ const handleError = (): void => {
91
97
  // user get error during playing ad
92
98
  // do nothing or whatever you want
93
99
  },
94
100
 
95
- const { show } = useAdsgram({ blockId: 'task-123', onReward: handleReward, onError: handleError });
101
+ const { show } = useAdsgram({ blockId: '123', onReward: handleReward, onError: handleError });
96
102
 
97
103
  return <button onClick={show}>Show Ad</button>;
98
104
  }
@@ -1,17 +1,5 @@
1
1
  import { BlockId, EventHandler } from "@adsgram/common";
2
2
  import React, { JSX } from "react";
3
- /**
4
- * Props for the AdsgramTask component
5
- * @interface TaskProps
6
- * @property {BlockId} blockId - The unique identifier for the task block
7
- * @property {boolean} [debug] - Whether to enable debug mode
8
- * @property {string} [className] - Additional CSS class names
9
- * @property {React.ReactNode} [children] - Child elements to render inside the task component
10
- * @property {EventHandler} [onReward] - Callback for reward events
11
- * @property {EventHandler} [onBannerNotFound] - Callback for banner not found events
12
- * @property {EventHandler} [onTooLongSession] - Callback for too long session events
13
- * @property {EventHandler} [onError] - Callback for error events
14
- */
15
3
  export interface TaskProps {
16
4
  blockId: BlockId;
17
5
  debug?: boolean;
@@ -27,8 +15,16 @@ export interface TaskProps {
27
15
  * Handles initialization and event binding for the Adsgram task functionality.
28
16
  *
29
17
  * @component
30
- * @param {TaskProps} props - Component properties
18
+ * @property {TaskProps} props - Component properties
31
19
  * @returns {JSX.Element | null} The rendered task element or null if not ready
20
+ * @property {BlockId} props.blockId - The unique identifier for the task block
21
+ * @property {boolean} props.debug - Enable debug mode to get test task from server
22
+ * @property {string} props.className - Additional CSS class names
23
+ * @property {React.ReactNode} props.children - Child elements to render inside the task component
24
+ * @property {EventHandler} props.onReward - Callback for reward events
25
+ * @property {EventHandler} props.onBannerNotFound - Callback for banner not found events
26
+ * @property {EventHandler} props.onTooLongSession - Callback for too long session events
27
+ * @property {EventHandler} props.onError - Callback for error events
32
28
  *
33
29
  * @example
34
30
  * ```tsx
@@ -6,8 +6,16 @@ import { useEffect, useRef, useState } from "react";
6
6
  * Handles initialization and event binding for the Adsgram task functionality.
7
7
  *
8
8
  * @component
9
- * @param {TaskProps} props - Component properties
9
+ * @property {TaskProps} props - Component properties
10
10
  * @returns {JSX.Element | null} The rendered task element or null if not ready
11
+ * @property {BlockId} props.blockId - The unique identifier for the task block
12
+ * @property {boolean} props.debug - Enable debug mode to get test task from server
13
+ * @property {string} props.className - Additional CSS class names
14
+ * @property {React.ReactNode} props.children - Child elements to render inside the task component
15
+ * @property {EventHandler} props.onReward - Callback for reward events
16
+ * @property {EventHandler} props.onBannerNotFound - Callback for banner not found events
17
+ * @property {EventHandler} props.onTooLongSession - Callback for too long session events
18
+ * @property {EventHandler} props.onError - Callback for error events
11
19
  *
12
20
  * @example
13
21
  * ```tsx
@@ -13,7 +13,7 @@ import type { AdsgramMethods, AdsgramProps } from "@adsgram/common";
13
13
  * @param {AdsgramProps} props - Configuration parameters for Adsgram initialization
14
14
  * @returns {AdsgramMethods} Methods to interact with the Adsgram sdk
15
15
  * @param {string} params.blockId - Unique identifier for the ad block
16
- * @param {boolean} [params.debug=false] - Enable debug mode
16
+ * @param {boolean} [params.debug=false] - Enable [debug](https://docs.adsgram.ai/publisher/api-reference#parameters) mode
17
17
  * @param {BannerType} [params.debugBannerType] - Forced banner type in debug mode
18
18
  * @param {HandlerType} [params.onReward] - Callback when user completes a rewarded ad
19
19
  * @param {HandlerType} [params.onError] - Callback when ad playback fails
@@ -5,7 +5,7 @@ import { useCallback, useEffect, useRef } from "react";
5
5
  * @param {AdsgramProps} props - Configuration parameters for Adsgram initialization
6
6
  * @returns {AdsgramMethods} Methods to interact with the Adsgram sdk
7
7
  * @param {string} params.blockId - Unique identifier for the ad block
8
- * @param {boolean} [params.debug=false] - Enable debug mode
8
+ * @param {boolean} [params.debug=false] - Enable [debug](https://docs.adsgram.ai/publisher/api-reference#parameters) mode
9
9
  * @param {BannerType} [params.debugBannerType] - Forced banner type in debug mode
10
10
  * @param {HandlerType} [params.onReward] - Callback when user completes a rewarded ad
11
11
  * @param {HandlerType} [params.onError] - Callback when ad playback fails
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@adsgram/react",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
+ "homepage": "https://docs.adsgram.ai/publisher/",
4
5
  "type": "module",
5
6
  "main": "dist/index.js",
6
7
  "types": "dist/index.d.ts",
@@ -12,7 +13,7 @@
12
13
  "README.md"
13
14
  ],
14
15
  "dependencies": {
15
- "@adsgram/common": "1.0.0"
16
+ "@adsgram/common": "1.0.2"
16
17
  },
17
18
  "devDependencies": {
18
19
  "@types/node": "^24.0.1",