goopubtag
Version:
React library for Google Publisher tag
147 lines (140 loc) • 4.99 kB
TypeScript
import * as react_jsx_runtime from 'react/jsx-runtime';
import { ReactNode } from 'react';
/** GPT types
* - reference: https://developers.google.com/publisher-tag/reference
* - Definitely typed: https://www.npmjs.com/package/@types/google-publisher-tag
*/
type Attributes = {
[key: string]: string;
};
type Size = readonly [number, number];
type Sizes = string | Size | Size[];
type SizeMapping = {
viewport: Size;
sizes: Sizes;
};
type PrivacySettings = {
limitedAds: boolean;
nonPersonalizedAds: boolean;
childDirectedTreatment: boolean;
restrictDataProcessing: boolean;
underAgeOfConsent: boolean;
};
type CollapseSlot = Collapse | 'expand_strict';
type Collapse = 'default' | 'expand' | 'collapse';
type AnchorSettings = Pick<SlotUnit, 'adUnit' | 'targetingArguments'> & {
position: 'top' | 'bottom';
};
type RewardedSettings = Pick<SlotUnit, 'adUnit' | 'targetingArguments'> & {
onReady?: (event: any) => void;
onClosed?: (event: any) => void;
onGranted?: (event: any) => void;
};
type OutOfPageTypes = {
type: 'anchor';
settings: AnchorSettings;
} | {
type: 'rewarded';
settings: RewardedSettings;
};
type OutOfPage = Pick<SlotUnit, 'adUnit' | 'targetingArguments'> & OutOfPageTypes;
type LazyLoad = {
fetchMarginPercent: number;
renderMarginPercent: number;
mobileScaling: number;
};
type AutoReload = Pick<SlotProvider, 'networkId' | 'personalizedAds' | 'singleRequest' | 'adUnit' | 'sizeMapping' | 'adSenseAttributes' | 'targetingArguments' | 'fallback' | 'lazyLoad'>;
type SlotRender = {
getSlotElementId: Function;
};
type SlotVisibilityChanged = {
getSlotElementId: Function;
};
type Event<T> = {
serviceName: string;
slot: T;
};
type SlotLoadEvent = Event<SlotRender>;
type SlotRenderEndedEvent = Event<SlotRender>;
type SlotViewableEvent = Event<SlotVisibilityChanged>;
type GPT = {
adUnit?: string;
sizeMapping?: SizeMapping[];
adSenseAttributes?: Attributes;
targetingArguments?: Attributes;
};
type SlotProvider = GPT & {
networkId: number;
personalizedAds?: boolean;
singleRequest?: boolean;
disableInitialLoad?: boolean;
limitedAds?: boolean;
autoLoad?: boolean;
lazyLoad?: boolean | LazyLoad;
autoReload?: AutoReload;
fallback?: Collapse;
outOfPage?: OutOfPage;
};
type SlotUnit = GPT & {
networkId?: string;
slotId: string;
sizes: Sizes;
outOfPage?: boolean;
fallback?: CollapseSlot;
onSlotLoad?: (event: SlotLoadEvent) => void;
onSlotIsViewable?: (event: SlotViewableEvent) => void;
onSlotRenderEnded?: (event: SlotRenderEndedEvent) => void;
shouldRefresh?: () => boolean;
};
/** Context types */
type SharedContextProps = SlotProvider & {
debug?: boolean;
};
type GPTProviderProps = SharedContextProps & {
children: ReactNode;
};
/** Component types */
type GPTSlotProps = SlotUnit;
/** Hook types */
type UseGPTProps = {};
type UseGPT = {
refresh: (adSlots?: string[]) => void;
setTargetingAttributes: (slotId: string, attributes: Attributes) => void;
setPageTargetingAttributes: (attributes: Attributes) => void;
clearTargetingAttributes: (slotId: string, attributes?: string[]) => void;
clearPageTargetingAttributes: (attributes?: string[]) => void;
setPrivacySettings: (settings: Partial<PrivacySettings>) => void;
};
declare const GPTProvider: (props: GPTProviderProps) => react_jsx_runtime.JSX.Element;
declare const GPTSlot: (props: GPTSlotProps) => react_jsx_runtime.JSX.Element;
declare const useGPT: (props?: UseGPTProps) => UseGPT;
declare const GUIDELINES: {
UNIT_SIZE: {
readonly BILLBOARD: readonly [970, 250];
readonly SKYSCRAPER_WIDE: readonly [300, 600];
readonly SKYSCRAPER: readonly [160, 600];
readonly SKYSCRAPER_SLIM: readonly [120, 600];
readonly LEADERBOARD_XL: readonly [970, 90];
readonly LEADERBOARD_LARGE: readonly [920, 90];
readonly LEADERBOARD: readonly [728, 90];
readonly MPU: readonly [320, 250];
readonly MPU_300: readonly [300, 250];
readonly MOBILE_LEADERBOARD_LARGE: readonly [468, 60];
readonly MOBILE_LEADERBOARD_MEDIUM: readonly [320, 100];
readonly MOBILE_LEADERBOARD: readonly [320, 50];
readonly LINE_TEXT_UNIT: readonly [280, 18];
readonly ONE_BY_ONE: readonly [1, 1];
readonly BLANK: readonly [0, 0];
readonly FLUID: "fluid";
};
SCREEN_SIZE: {
readonly DESKTOP_LARGEST: readonly [1220, 0];
readonly DESKTOP_PLUS: readonly [970, 0];
readonly DESKTOP: readonly [861, 0];
readonly TABLET_PLUS: readonly [728, 0];
readonly TABLET: readonly [600, 0];
readonly MOBILE_PLUS: readonly [468, 0];
readonly MOBILE: readonly [320, 0];
};
};
export { GPTProvider, GPTProviderProps, GPTSlot, GPTSlotProps, GUIDELINES, Sizes, SlotLoadEvent, SlotRenderEndedEvent, SlotViewableEvent, UseGPTProps, useGPT };