XF 2.1 Passing Thread Tags to Google DFP

chris TFF

Member
Hello,

We pass a number of variables, such as thread ID and forum ID to our Google DFP installation to help target our adverts.

We would also like to pass Thread Tags and User Group IDs. We have tried a few code variations, but have't made them work. Both would be arrays.

We have managed to pass a specific Usergroup ID - but ideally we need to pass all of them.

Can anyone help with the right code please?

This is what we are using so far:

Code:
<xf:if is="{$forum.node_id}">
      <!-- Forum ID: {$forum.node_id} -->
            googletag.pubads().setTargeting("Forum_ID","{$forum.node_id}");
      </xf:if>
        
            <xf:if is="{$threadID|raw}">
               <!-- THREAD ID: {$threadID|raw} -->
               googletag.pubads().setTargeting("THREAD_ID","{$threadID|raw}");
            </xf:if>
        
            <xf:if is="{{$xf.visitor.isMemberOf([43])}}">
                <!-- UG: Sugar Beet Grower-->
                googletag.pubads().setTargeting("USERGROUP","43");
            </xf:if>
 
Working on this further ourselves - the value:

$thread.tags

is not available in the header.

In the Thread_View template, we can set:

Code:
<xf:page option="threadTags" value="{$thread.tags}" />

This makes $threadTags available in the header.

But if you output $threadTags or $threadTags|raw at the header level is just passes the word "Array".

We need the ouput in this format in the header to pass the tags to Google DFP:

Code:
googletag.pubads().setTargeting('XFTAG', ['value1', 'value2', 'value3'])
basically need to build this: 'value1', 'value2', 'value3'

You can also loop though thread tags at the thread_view template level looking for particular tags and setting a value and that works to (but we have over 5000 tags in our dataset):

Code:
<xf:foreach loop="$thread.tags" value="$tag">
    <xf:if is="$tag.tag == 'blackgrass'">
        <xf:page option="threadTags" value="tagBlackgrass" />
    </xf:if>
    <xf:if is="$tag.tag == 'pixelexit'">
        <xf:page option="threadTags" value="tagPixelexit" />
    </xf:if>
    <xf:if is="$tag.tag == 'customtag'">
        <xf:page option="threadTags" value="tagCustomtag" />
    </xf:if>
</xf:foreach>

But how do you build an array that will pass accross in the header?

@Chris D what are we missing
 
Last edited:
Top Bottom