Adsense supports associating up to 5 custom channels with an ad unit by separating the channel numbers with '+':

google_ad_channel = "12345678+3249087521+3275987324";

(see also https://www.google.com/adsense/support/bin/answer.py?answer=50680&topic=152)

Rudimentary support for that kind of multiple-channel ad unit would be as easy as allowing the $channel parameter in _adsense_format to be a string, and only indirecting using variable_get if it were an integer.

CommentFileSizeAuthor
#12 118876_0.patch6.21 KBWesley Tanaka
#2 118876.patch623 bytesWesley Tanaka

Comments

kbahey’s picture

That is a relatively new features.

Can you create a patch? Please make sure that the User Interface for blocks, function calls, and embedded tags are all consistent.

Wesley Tanaka’s picture

Status: Active » Needs review
StatusFileSize
new623 bytes

This allows calls to adsense_display to optionally set the channel string manually, by passing a string instead of an integer.

Wesley Tanaka’s picture

which is, by the way, a nice feature to have even when you have a lot of custom channels and are creating classic single-channel ad units . . .

kbahey’s picture

Status: Needs review » Needs work

Yes, that is a first step though.

What about the UI for the blocks? Right now it is a drop down list with numeric keys.

Wesley Tanaka’s picture

Those should all still work perfectly fine! (The filter tags should continue working too!)

As far as the filter tags, do you want the _adsense_process_tags regexes expanded to include 'plus-separated-numbers'? The problem there is distinguishing robustly whether a single number is a literal channel or an ADSENSE_AD_CHANNEL index. You could pick a magnitude cut-off, but that's a hack.

If you're thinking about replacing a drop-down-list UI with something more difficult (like a text field) that allowed multiple channels, why not go all the way and get rid of all the ADSENSE_AD_CHANNEL stuff completely, and use string channels everywhere?

kbahey’s picture

Wesley

Yes, the filter could be taken care of in your solution.

The part I am not sure would work, is this:

What we have now is that you define channels in admin/settings/adsense. All the channels are then available as drop down lists. The admin goes to the block page, and assigns a channel to a block. He then publishes that block anywhere (e.g. in the header, or footer, ...etc.).

In your proposal, the channels are no longer 1:1, but they can be cumulative.

So, we need to find a solution to the UI that preserves the simplicity (all channels defined in one place), yet offers the new flexibility of having more than one channel assigned to a given block. A drop down list as it is is not possible. Perhaps a multi select list, or a list of defined channels with a check box is best.

Maybe we need a new table that stores the channel info, and assigns a friendly name to each (normally maps to a Google channel name that you assign).

In any case, such a solution preserving "define channels once, use them anywhere" will allow the reuse of channels without suffering from typos, long meaningless numbers as identifiers, ...etc.

I hope this clears out my point of view.

Wesley Tanaka’s picture

I think I understand where you're coming from. You see the design goal of the adsense module as following along with, and replicating a portion of the functionality of the "adsense setup" wizard (https://www.google.com/adsense/code)

The ADSENSE_AD_CHANNEL variables are for storing a mirror of up to ADSENSE_MAX_CHANNELS of your custom channels, and refer to them with integers instead of names.

And adsense_display(), the filters, and the block setup are *replacements* for going through https://www.google.com/adsense/code

The reason that wasn't initially clear to me is that ADSENSE_MAX_CHANNELS is defined to be 7, which is *much* smaller than the google limit of 200. I didn't how the module was supposed to work if you wanted to use more than 7 different channels. Increasing ADSENSE_MAX_CHANNELS to 200 would make things more confusing, because instead of worrying about a google channel ID, you now have to worry about a google channel ID and also an integer between 1 and 200.

I've actually been commenting out that variable_get look-up (similar to the patch I submitted here) and using channel ID strings directly because I didn't want to deal with that extra ADSENSE_AD_CHANNEL index.

Given where you're coming from, I have three ideas.

1. Do the obvious extention. A checkbox set/multi-select menu for the block setup, a list/array of ADSENSE_AD_CHANNEL indexes for the filter tag and the adsense_display call. I am uninterested in doing a patch for this, because with large numbers of channels, the ADSENSE_AD_CHANNEL variables become too much to deal with. Plus, it would still require me to maintain a patch on top of the stock module (at the very least, increasing the value of ADSENSE_MAX_CHANNELS).

In any case, something like the patch above is a requied step for this kind of change. If you'd prefer array() instead of string, that'd be easy to change.

2. Get rid of ADSENSE_AD_CHANNEL variables completetly. Use channel IDs instead of ADSENSE_AD_CHANNEL variables. Create an extra "friendly name" which could be associated with channel IDs. Everything else as above, except that the "friendly name" would be used instead of the channel ID for display in UIs.

Personally, I find it more comfortable (and less error prone) to generate a (possibly multiple) channel ID using the google UI and then cut and paste that channel ID than I find generating a channel ID, looking at the adsense settings page to find which of {1..200} it is, then using that number. And certainly much easier than trying to remember which of the numbered channels in the variable table corresponds to which channel name in google.

Again, the patch submitted above would be a required step for this change.

3. Change the design goal. What if the adsense module tried to, as much as possible, leverage google's adsense setup wizard (https://www.google.com/adsense/code)?

Here's one possibility: There would be a page on the site where you could paste wholesale a google-generated adsense block. You submitted that block, and the page would generate for you both a filter tag and an adsense_display() PHP call.

The block config would also contain a text field where you could paste a google generated adsense block.

You could get rid of the database and UI for ADSENSE_AD_CHANNEL variables, as well as the ADSENSE_COLOR_ variables. You could get rid of adsense_ad_formats(), as all these things could be pulled from the pasted block.

It would be less error prone than the current model, in that you'd be cutting and pasting the entire generated adsense code block. Google doesn't let you even select less than the whole block.

This UI would be forward compatible with future google adsense features.

It would cut back on variable lookup calls, which couldn't hurt performance, and the module file itself might end up smaller.

kbahey’s picture

So far, those who need more channel could do so by modifying the max channel define. Of course, having 200 is not feasible, but so far, I have not needed that much anyways.

As for the options:

Option 3 is out of the question: the reason is that the whole premise of the module is to avoid copying and duplicating code around, for example you change the theme, and want to change the color scheme, you just change the group and it changes all the blocks using that group. The focus is ease of use for users.

Option 1 is the natural progression, but rather than store this in a variable_get() thing, we now have a new table called adsense_channels (channel id, channel name). channel ID is the same as in Google Adsense interface.

The user needs to enter a channel in Drupal just once, then using a collapsible/collapsed interface that has checkboxes, one can select one or more channels now for each block, and

So, instead of the block config in the variable table being:
adsense_ad_block_0 -> s:10:"468x15:1:2";

It would be:
adsense_ad_block_0 -> s:n:"468x15:1:222222";

Or for multiple channels:
adsense_ad_block_0 -> s:n:"468x15:1:1111111+222222+333333";

An _update() function would be needed to transform the old format to the new one, but that is not too much of a concern.

I think this then becomes more of an Option 2, or a hybrid, but you get my drift.

What do you think?

Wesley Tanaka’s picture

I get your point about themes. One could support that in option 3 by adding a "color group" index to the UI.

But let's focus on the smaller change described in #8. If we do get rid of the ADSENSE_AD_CHANNEL variables (hooray!), then I believe there's one more change necessary: to the filter tags, which would change in syntax from:

[adsense:piggy:1:1]
to
[adsense:piggy:1:35250938] for a single channel
or
[adsense:piggy:1:35250938+235987752+34598235] for multiple channels

(I don't fully understand these tags, but I'm describing them anyway after reading _adsense_process_tags(), so please correct me if I'm wrong)

Thus these things would need to change:

1. the change to adsense_display in the patch above
2. the change to blocks and the new table that you just described
3. the change to _adsense_process_tags (it looks like only the patterns needs to change?) described here
4. update functions for the blocks and tags

The variables could optionally remain in the variables table (?) to support previous adsense_display calls. If not, the patch in #2 could be made stronger -- support for integers could be dropped.

Wesley Tanaka’s picture

And by "piggy" in the above example, I mean "468x60" =)

kbahey’s picture

I get your point about themes. One could support that in option 3 by adding a "color group" index to the UI.

It is already there now. The admin/settings/adsense page has "groups" which are combinations of colors.

But let's focus on the smaller change described in #8. If we do get rid of the ADSENSE_AD_CHANNEL variables (hooray!), then I believe there's one more change necessary: to the filter tags, which would change in syntax from:

[adsense:piggy:1:1]
to
[adsense:piggy:1:35250938] for a single channel
or
[adsense:piggy:1:35250938+235987752+34598235] for multiple channels

(I don't fully understand these tags, but I'm describing them anyway after reading _adsense_process_tags(), so please correct me if I'm wrong)

The tags are direct maps to the adsense_display() function, after some parsing of course.

Yes, that seems to be the direction we should take. If we take it a step further and make the channel the key, and have a description for it, this will replace the existing (small number).

So instead of 0, 1, 2, 3, ..etc. we will have 1232344 => channel1, 8483883 => channel2, ...etc.

Thus these things would need to change:

1. the change to adsense_display in the patch above
2. the change to blocks and the new table that you just described
3. the change to _adsense_process_tags (it looks like only the patterns needs to change?) described here
4. update functions for the blocks and tags

Yes, but if we do the channel_number => channel_name above, the above will be mostly the same.

The variables could optionally remain in the variables table (?) to support previous adsense_display calls. If not, the patch in #2 could be made stronger -- support for integers could be dropped.

I guess they could stay. Up to 10-20 channels is not a big deal anyway. Remember that variables are cached and loaded for every page request, so we need to keep them small.

Wesley Tanaka’s picture

Status: Needs work » Needs review
StatusFileSize
new6.21 KB

So would it be possible to commit the small patch above as a first step?

I started looking into doing the whole thing, but it would require significant changes to the settings page (in that it can't be processed with system_settings_form anymore), or the channel definition would have to go into its own form.

Here's a little bit of work toward getting this done, if that's useful to you. I noticed that the install file is a bit weird: adsense_update_1 is calling adsense_install, which means that any tables created in the install get called again in update_1? They have "IF NOT EXISTS", but it still seems strange.

Wesley Tanaka’s picture

Let me clarify:

Would it be possible to commit http://drupal.org/files/issues/118876.patch as a first step?

Wesley Tanaka’s picture

Thinking about this some more, what might be more useful is a function which accumulates channel IDs in a static variable, and appends them with variables passed as parameters to the adsense_display() call.

An example of how this might be used:

A function in a phptemplate theme would detect that the URL is /forum/something, and call adsense_channel_add('02398750'), where 02398750 is a channel ID corresponding to "forum section". A custom module then calls adsense_channel_add('49793234'), where 49793234 is the "profile: female" channel ID. Later on in the theme, adsense_display('928357') is called where 928357 is the "between the topic and comments" channel. Even later, in one of the blocks, adsense_display('43298') is called where 43298 is the "all pages right sidebar" channel.

The two ad blocks would then have these channels set:

1. forum section + profile: female + between topic and comments
2. forum section + profile: female + all pages right sidebar

Bevan’s picture

I've contributed a few thoughts related to how this could work in this related thread: http://drupal.org/node/144416

When support for multiple ch IDs is available, I believe the interface for selecting channels should be a list of checkboxes or multiple select list (if more than, perhaps 20, channels are defined). adsense_display() would also need to allow for no channels.

jcnventura’s picture

Status: Needs review » Closed (won't fix)

This discussion is obsolete. Everyone is encoraged to migrate to the new ad formats where this type of thing is outside the scope of the AdSense module.