I want to pass referring URL as an attribute to DFP. I believe if I were to build a custom module and use google_admanager_add_attribute that would prevent my page caching from functioning, as each visitor should have a different referring url, and therefore would require different HTML, therefore preventing the page from being cached. I believe I avoid this issue by passing back the referring URL information client side via javascript, versus server side.

In order to do this, I need to ensure my GA_googleAddAttr is called at the right point in the scripts execution - after the first call to DFP is made, but before the call to display the ads is made - any idea how I would go about doing this via the Google Ad Manager module?

Comments

jcisio’s picture

Status: Active » Fixed

You set your value first. Then in your module, use google_admanager_get_js() to insert pure JS code in the attr section.

newmediaist’s picture

What hook_ would be the best place to put the call to google_admanager_get_js(), hook_boot() ?

jcisio’s picture

I don't know. It depends. Test and see.

newmediaist’s picture

I've been testing and can't seem to get it to work; My code is as follows:

function google_admanager_targeting_init() {
    if (module_exists('google_admanager')) {
    	$external_js = file_get_contents(drupal_get_path('module', 'google_admanager_targeting') . '/google_admanager_targeting.js');
    	google_admanager_get_js($external_js);
    }
}

Although Drupal does not throw any errors, the JS code is not being inserted into the page... I've also tried hook_boot and hook_preprocess_page with no success - any suggestions are appreciated!

newmediaist’s picture

Status: Fixed » Active

Also, why do you recommend using google_admanager_get_js rather than google_admanager_add_js when what I want to do is add JS?

newmediaist’s picture

Status: Active » Closed (fixed)

Just wanted to follow up to let anyone reading this post down the road that the following code worked for me:

/**
 * Implementation of hook_init().
 */
function google_admanager_targeting_init() {
    if (module_exists('google_admanager')) {
    	$external_js = file_get_contents(drupal_get_path('module', 'google_admanager_targeting') . '/google_admanager_targeting.js');
    	google_admanager_add_js($external_js, 'attr');
    }
}
jcisio’s picture

I take this chance to fix the wrong description of google_admanager_add_js() where the 'attr' section was missing.

jcisio’s picture

Yes, and of course it was a spelling mistake in #1.