react-dfp
react-dfp copied to clipboard
setTargetingArguments Overrides Slot Level Ad Targeting
I would like to add page level targeting to my ad slots on page change and I'm doing by writing a useEffect hook that sets the targeting to incoming parameters. However, setting the arguments through setTargetingArguments
overrides the slot level targeting ads that I set up.
The code goes something like this (I will create a code sandbox example later):
For the Component that includes the Slot Provider:
const AdProvider = ({ targetingArgs }) => { useEffect(() => { const { urlPath } = targetingArgs; const { pathname } = window.location; DFPManager.setTargetingArguments({ urlPath, pathname }); }, [targetingArgs]); }
For the component that contains the AdSlots:
const AdInstance = ({ AdTargetingArgs }) => { return <AdSlot targetingArguments={{ customKw2: 'hello' }} /> }
I am not sure if this is the intended behavior of the setTargetingArguments. But if it is, can I create a PR that ads more methods to the manager to set up only page level or slot level targeting?
This sort of relates to #204
I created a comprehensive example of the situation in the following sandbox:
https://codesandbox.io/s/react-dfp-targeting-spmhy4
Ignoring the multiple logs, and the inconsistencies that occasionally occur between the Refreshable and Registered Slots, it all boils down to the setTargetingArguments
method.
If you uncomment line 17 in the sandbox provided below, you can see that all the Registered slot level targeting values get overridden with the new values.
Again, not sure if this is the desired behavior, but it would be nice to have a more granular control over the setTargeting behavior.
Some interesting observations:
Note that the actual googletag slots do not update unless line 18 is uncommented and replaced with a reload, then they would be overridden like the DFP registered ones.
Not sure how the DFM refresh
is behaving even after reading the source code, especially since the registered slots are the same as the refreshable ones in this example.
Hi @Mohamad-Kamar , sorry about the delay in my response, did you figure this out?
I'm facing this issue. Any progress?
@sectsect We did end up finding a fix, but I can't remember what it was since this was in my old company and I haven't worked on that codebase for quite a while now. Sorry 😅 .