npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-dfp-hyperloop

v0.3.6

Published

Gpt/dfp components that you can easily use in your isomorphic react apps. This package is inspired in the awesome library [jquery.dfp](https://github.com/coop182/jquery.dfp.js), and aims to provide its same ease of usage but, of course, taking into consid

Downloads

4

Readme

React DFP

Gpt/dfp components that you can easily use in your isomorphic react apps. This package is inspired in the awesome library jquery.dfp, and aims to provide its same ease of usage but, of course, taking into consideration the react concepts & lifecycle features.

Install:

npm install --save-dev react-dfp

Usage + Demos

  1. Create the adslots:
   import { DFPSlotsProvider, AdSlot } from 'react-dfp';
   
   <DFPSlotsProvider dfpNetworkId={'9999'} adUnit={"foo/bar/baz"} ... >
     ...
      <AdSlot sizes={[ [900, 90], [728, 90]]} />
     ...
      /* you can override the props */
      <AdSlot adUnit={"home/mobile"} sizes={[ [300, 250], [300, 600]]} />
     ...
   </DFPSlotsProvider>
  1. (Optional) Render or refresh the ads:
import { DFPManager } from 'react-dfp';
...
/* If you are using ``` <DFPSlotsProvider> ``` the following call won't be required,  
 * unless you has set the property ``` autoLoad={false} ```.
 */
DFPManager.load();
...
DFPManager.refresh();
  1. Examples:

3.1) Example 1: Basic:

import React from 'react';
import ReactDom from 'react-dom';
import { DFPSlotsProvider, AdSlot } from 'react-dfp';

ReactDom.render( 
  <DFPSlotsProvider dfpNetworkId='9999' targetingArguments={ {'customKw': 'test'} }
                sizeMapping={ [ {viewport: [1024, 768], sizes:[[728, 90], [300, 250]]},
                                {viewport: [900, 768], sizes:[[300, 250]] }] }>
    <div className="desktop-ads">
      <AdSlot sizes={[[728,90], [300, 250]]} adUnit='homepage/1' />
    </div>
    <div className="mobile-ads">
      <AdSlot sizes={[[320,50], [300, 50]]} adUnit='homepage/mobile' />
    </div>
    ...
  </DFPSlotsProvider>,
document.querySelectorAll(".ad-container")[0]);

3.2) Example 2: (manually) oad and refresh ads.

import React from 'react';
import ReactDom from 'react-dom';

import {AdSlot, DFPManager} from 'react-dfp';

function loadSecondaryAd() {
    ReactDom.render(<AdSlot sizes={[[300, 250]]}
                         dfpNetworkId='9999'
                         adUnit='homepage/2'
                         />,
                    document.querySelectorAll(".ad-container-2")[0]);
}

ReactDom.render( <AdSlot sizes={[[728,90], [300, 250]]}
                         dfpNetworkId='9999'
                         adUnit='homepage/1' 
                         targetingArguments={ {'customKw': 'test'} }
                         sizeMapping={ [ {viewport: [1024, 768], sizes:[[728, 90], [300, 250]]},
                                         {viewport: [900, 768], sizes:[[300, 250]] }] }
                         onSlotRender={loadSecondaryAd}
                         /* never refresh this adSlot */
                         shouldRefresh={ ()=> false }
                         />,
                document.querySelectorAll(".ad-container")[0]);
DFPManager.setTargetingArguments({'key': 'oh'});

// refresh ads every 15 seconds
window.setInterval(function refreshAds() { DFPManager.refresh(); }, 15000);

DFPManager.load();

Options

DFPSlotsProvider

| Property | Type | Example | Description | | ------------------ | ------------- | ----------- | ------- | | autoLoad | bool (default true) | { false } | Tell to the provider if it should load the ads when the slots are mounted. | | dfpNetworkId | string | "1122" | DFP Account id. | | adUnit | string | "homepage" | The adunit you want to target the boxes (children / contained boxes). | | sizeMapping | array of objects. | { [ {viewport: [1024, 768], sizes:[[728, 90], [300, 250]]}, {viewport: [900, 768], sizes:[[300, 250]] }] } | Set the size mappings to be applied to the nested ad slots. | | targetingArguments | object | { "keywords": "family", "content": "test" } ``` | Object with attributes you want to add to the boxes (you can use for custom targeting) |

AdSlot

| Property | Type | Example | Description | | ------------------ | ------------- | ----------- | ------- | | dfpNetworkId | string (required) | "1122" | DFP Account id. | | adUnit | string (required) | "homepage" | The adunit you want to target to this box. | | sizes | array (required) | [ [300, 250], [300, 600], 'fluid' ] | list of sizes that this box support. Sizes can be specified by eigther and array like [width, height] or with strings ("dfp named sizes") like 'fluid'. You can configure 1 or more sizes.| | sizeMapping | array of objects. | { [ {viewport: [1024, 768], sizes:[[728, 90], [300, 250]]}, {viewport: [900, 768], sizes:[[300, 250]] }] } | Set the size mappings to be applied to the adSlot. | | targetingArguments | object (optional) | { "keywords": "family", "content": "test" } | Object with attributes you want to add to this box (you can use for custom targeting) | | onSlotRender | fcn. (optional) | function(eventData) { console.log(eventData.size); } | This callback is executed after the adSlot is rendered. The first argument passes the gpt event data (googletag.events.SlotRenderEndedEvent). | | shouldRefresh | fcn. (optional) (should return a boolean)| function() { /* never refresh this ad */ return false; } | Return a boolean that tells the dfp manager whether the ad slot can be refreshed or not. | | slotId | string. (optional) | "homepage-leadboard" ``` | Controls the id of the dom element in which the dom is displayed. If this field is not provided a random name is created. |

DFPManager

Public methods

| Property | Type | Example | Description | | ------------------ | ------------- | ----------- | ------- | | load | fcn([slotId]) | DFPManager.load(); | Fetches the gpt api (by calling init()) and renders the ad slots in the page. You can specify an individual slot. | | refresh | fcn() | DFPManager.refresh(); | Refreshes the ad slots available in the page. This method will call load() if it wasn't already called. Use the method <AdSlot shouldRefresh={function(){}} ...> to get control over the slots to be refreshed. | | targetingArguments | object (optional) | { "keywords": "family", "content": "test" } | Object with attributes you want to enable globaly (you can use this for custom targeting) | | getGoogletag | fcn() => Promise | DFPManager.getGoogletag().then( googletag => { console.log(googletag); }); | Returns a promise that resolves when the object googletag object is ready for usage (if required this fcn makes the network call to fetch the scripts). |

For Internal Usage Only

| Property | Type | Example | Description | | ------------------ | ------------- | ----------- | ------- | | init | fcn() => Promise | DFPManager.init(); | Initializes the dfp manager (fetches the gpt scripts from network). Returns a promise that resolves when the gpt api is ready for usage. | | attachSlotRenderEnded | fcn( fcn({slotId, event}) ) | DFPManager.attachSlotRenderEnded((id, event) => {console.log(event.size); }) | Attaches a callback that will be called when an ad slot is rendered (or refreshed). slotId is the id of slot. event is the gpt event data. | | detachSlotRenderEnded | fcn(callback) | DFPManager.detachSlotRenderEnded(myCallback) | Detaches the callback. | | getRegisteredSlots | fcn() => {} | Object.keys(DFPManager.getRegisteredSlots()) | Returns an object whose attributes are the registered slots. Example: { slotId: { data }, .... }| | getRefreshableSlots | fcn() => { slotId:{ slot }, ... } | console.log(DFPManager.getRegisteredSlots().length); | Returns an object whose properties are slots that can be refreshed (see property shouldRefresh ). | | getTargetingArguments | fcn() => {} | Object.keys(DFPManager.getTargetingArguments()) | Returns an object that contains the targeting arguments (configured through DFPManager.setTargetingArguments()) | | getSlotTargetingArguments | fcn(slotId) => {} | console.log(DFPManager.getSlotTargetingArguments('slot-five')['the-key']); | Returns an object that contains the custom targeting arguments that were set for the given slot (slotId). |

Wanna help?

I certainly know that testcases need to be improved, but, as long as your syntax is clean, submit testscases and, of course, all the interfaces are kept working, all kind of contribution is welcome.

Complains.

Pull requests are welcome 🍻.