Documentation ¶
Overview ¶
Package ads implements a small reusable app for easily displaying adversitesements from different providers.
To use this application, import it somewhere in your code, include it into your main app and set the PublisherID field in the providers you plan to use.
import ( ... "gnd.la/apps/ads" ... ) ... ads.AdSense.PublisherID = "ca-pub-123456" App.Include("/ads", ads.App, "")
Then, from your templates you can use the template function "ad". See Ad for its documentation.
Additionaly, this app also exports a Javascript API, but using it is not required. The only exposed function is.
Ads.Init(options)
If you use this function, you should usually call it from a handler attached to the document.ready event:
$(document).ready(function() { Ads.Init({ Google: true, Chitika: false }); });
The options parameter allows selectively disabling ads from one or several providers (e.g. displaying ads for free users and hiding them for paid users, or showing ads from each provider 50% of time). Finally, if this function has not been called by the time window.load trigers, it will be automatically called with no options, loading all the ads present in the page. Note that ads hidden via CSS (e.g. using media queries) will always be removed.
Index ¶
Constants ¶
const ( // Top and Bottom represent the ad position when it's displayed // as Fixed ad. Top = "Top" Bottom = "Bottom" // Fixed displays the ad in a fixed position, either // at the Top or the Bottom. When using Fixed as an // option, either Top or Bottom must be used too. Fixed = "Fixed" )
Variables ¶
var ( // AdSense implements a Provider which displays Google's AdSense ads. // For more information, see http://www.google.com/adsense/. // // AdSense supports the following ad sizes: // Size120x90, Size120x240, Size120x600, // Size125x125, Size160x90, Size160x600, Size180x90, // Size180x150, Size200x90, Size200x200, Size234x60, // Size250x250, Size300x250, Size300x600, // Size300x1050, Size320x50, Size320x100, // Size336x280, Size468x15, Size468x60, Size728x15, // Size728x90, Size970x90, Size970x250, // SizeResponsive. AdSense = &Provider{ Name: "AdSense", URL: "http://www.google.com/adsense/", script: "//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js", defaultSlot: "", requiresSlot: true, responsive: true, render: renderAdSenseAd, className: "ads-adsense", } // Chitika implements a Provider which displays Chitika ads. // For more information, see http://www.chitika.com. // // Chitika supports the following ad sizes: // Size120x600, Size160x160, Size160x600, // Size200x200, Size250x250, Size300x150, // Size300x250, Size300x600, Size336x280, // Size468x60, Size468x180, Size468x250, // Size500x200, Size500x250, Size550x120, // Size550x250, Size728x90, SizeResponsive. Chitika = &Provider{ Name: "Chitika", URL: "http://www.chitika.com", script: "//cdn.chitika.net/getads.js", defaultSlot: "Chitika Default", requiresSlot: false, responsive: true, render: renderChitikaAd, className: "ads-chitika", } )
var (
App = app.New()
)
Functions ¶
func Ad ¶
func Ad(ctx *app.Context, provider *Provider, slot string, s Size, options ...string) (template.HTML, error)
Ad returns the HTML for an ad with the given provider, slot ID, size and options. This function is exported as a template function named "ad". Note that the first argument (the *app.Context) is implicit and passed by the template VM.
Some examples ¶
To insert a 728x90 ad, use:
{{ ad @Ads.AdSense "123456789" @Ads.Sizes.S728x90 }}
To insert a responsive ad fixed at the bottom, use:
{{ ad @Ads.AdSense "123456789" @Ads.Sizes.Responsive @Ads.Fixed @Ads.Bottom }}
Types ¶
type Provider ¶
type Provider struct { Name string URL string PublisherID string // contains filtered or unexported fields }
Provider represents an ad provider. Users should not create their own providers, but use the available ones. See AdSense and Chitika.
type Size ¶
type Size uint32
Size represents the ad size. Use the available constants in this package to
const ( Size120x240 Size = Size(120<<16 | 240) Size120x600 Size = Size(120<<16 | 600) Size120x90 Size = Size(120<<16 | 90) Size125x125 Size = Size(125<<16 | 125) Size160x160 Size = Size(160<<16 | 160) Size160x600 Size = Size(160<<16 | 600) Size160x90 Size = Size(160<<16 | 90) Size180x150 Size = Size(180<<16 | 150) Size180x90 Size = Size(180<<16 | 90) Size200x200 Size = Size(200<<16 | 200) Size200x90 Size = Size(200<<16 | 90) Size234x60 Size = Size(234<<16 | 60) Size250x250 Size = Size(250<<16 | 250) Size300x1050 Size = Size(300<<16 | 1050) Size300x150 Size = Size(300<<16 | 150) Size300x250 Size = Size(300<<16 | 250) Size300x600 Size = Size(300<<16 | 600) Size320x100 Size = Size(320<<16 | 100) Size320x50 Size = Size(320<<16 | 50) Size336x280 Size = Size(336<<16 | 280) Size468x15 Size = Size(468<<16 | 15) Size468x180 Size = Size(468<<16 | 180) Size468x250 Size = Size(468<<16 | 250) Size468x60 Size = Size(468<<16 | 60) Size500x200 Size = Size(500<<16 | 200) Size500x250 Size = Size(500<<16 | 250) Size550x120 Size = Size(550<<16 | 120) Size550x250 Size = Size(550<<16 | 250) Size728x15 Size = Size(728<<16 | 15) Size728x90 Size = Size(728<<16 | 90) Size970x250 Size = Size(970<<16 | 250) Size970x90 Size = Size(970<<16 | 90) )
const ( // SizeResponsive generates a responsive ad, which // adapts its size to the web browser screen size. SizeResponsive Size = 1 )