• Resolved sncooke

    (@sncooke)


    I need to pass the categories associated with a post to Google Ad manager using this format in the GAM code:

    googletag.pubads().setTargeting(‘category’, [‘category-1’, ‘category2’, ‘category3′]);

    where category-1, category-2, etc. are the categories associated with the current post.

    I know there is a shortcode in AdInserter to get the post categories:

    [adinserter data=’categories’]

    But I think this would return the categories comma separated.

    Is there a way to add the categories to the .setTargeting code above in the format required by Google Ad manager?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Spacetime

    (@spacetime)

    You can use a shortcode to get a single category name:

    [adinserter data='category-n']

    or single category slug:

    [adinserter data='category-slug-n']

    https://adinserter.pro/documentation/manual-insertion#shortcodes

    I’ll consider adding support to generate all shortcodes with single quotes for direct insertion.

    Thread Starter sncooke

    (@sncooke)

    Thanks – I’ve already got this working with a single category – but that doesn’t help when there are multiple categories associated with a post. As a current example, we have a client who wants to target all articles from the area “crowthorne”. We do categorise articles with local place names.

    An example article has the following categories:

    featured
    news
    crowthorne

    But if a visitor is looking at the story in say the “news” section the category picked up for .setTargeting would just be : googletag.pubads().setTargeting(‘category’, [‘news′]);

    So even though the article has a category of “crowthorne” assigned as well as “news” then “crowthorne” doesn’t get passed to GAM for it to be targeted with an ad.

    So being able pass categories in they way Google Ad Manager needs them would be fantastic.

    Currently trying to figure this out with custom code – but a native shortcode in AdInserter would be fantastic!

    Hope this all makes sense!

    Plugin Author Spacetime

    (@spacetime)

    You can try the latest development version:
    https://downloads.wordpress.org/plugin/ad-inserter.zip

    Addes support for
    [adinserter data='categories-single-quotes']
    and
    [adinserter data='categories-double-quotes']

    So you should use:
    googletag.pubads().setTargeting('category', [[adinserter data='categories-single-quotes']]);

    Thread Starter sncooke

    (@sncooke)

    Works a treat – I can stop pulling my hair out trying to custom code this now!

    Thanks

    Stuart

    Plugin Author Spacetime

    (@spacetime)

    🙂

    Works a treat

    Please say it here:
    https://wordpress.org/support/plugin/ad-inserter/reviews/#new-post

    Thank you!

    Does this work with custom taxonomies?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Passing Categories to Google Ad Manager’ is closed to new replies.