Tracker1 Tracker1 - 5 months ago 208
Javascript Question

How do I use reactjs with Google DFP/AdSense

I'm wanting to build a project with Facebook's reactjs framework (JSX), but given how it renders, how would I use this with Doubleclick for publishers?

If I trigger adsense/urchin, how do I tell React not to change/update those items?

Is there an alternative adwords script/interface I can use?


(will clean up this answer with a jsx example when I have one, for now...)

Thanks to rcs in freenode #reactjs:

rcs> tracker1: componentDidMount and make sure 
you're not throwing it away when you don't mean to

tracker1> rcs: so use componentDidMount for adsense/dfp 
binding, and simply don't change the render output?

rcs> tracker1: Yeah. Your render should write out the 
<ins class="adbygoogle" data-analytics-uacct ..... > 
piece, and you should fire off the adsbygoogle.push in 

tracker1> cool... didn't think it would be that easy for 
some reason...

rcs> tracker1: Or for dfp, handle the defineAdSlot in CDM, 
and googletag.pubads().refresh() on something that fires 
after they're all written out.

rcs> The thing that will trip you up is if you're firing 
things that make React thing that written node needs to get 
removed and replaced, instead of moved, etc.

rcs> But that shouldn't be a primary worry -- just something 
to keep in the back of your head if you're seeing more 
impressions/ad loads than you should be.

tracker1> they'll only change on a navigation/route change

rcs> Keep in mind that adsense TOS is vague on ajax page loads.
rcs> Or 'client side' page loads.

(fix apos)