Google Analytics

Tracking Code: Campaign Tracking

This reference describes the methods that you use for setting up and customizing campaign tracking in Google Analytics reporting.

GATC Campaign Tracking Methods

Method Details

_setAllowAnchor()

_setAllowAnchor(bool)

This method sets the # sign as the query string delimiter in campaign tracking. This option is set to false by default.

Conventional campaign tracking URLs use the question mark (?) to indicate the beginning of key/value pairs that make up the query. If you set this option to true, your campaign tracking URLs can use a pound (#) sign instead of the question mark (?) to indicate the beginning of the query string.

Async Snippet (recommended)
http://mysite.net/index.html#utm_source=In+House&utm_medium=email&utm_campaign=Fall+email+offers
_gaq.push(['_setAllowAnchor', true]); 

parameters

Boolean  true or false  If this parameter is set to true, then campaign uses anchors. Otherwise, the campaign uses search strings.

_setCampContentKey()

_setCampContentKey(newCampContentKey)

Sets the campaign ad content key. The campaign content key is used to retrieve the ad content (description) of your advertising campaign from your campaign URLs. Use this function on the landing page defined in your campaign.

For example, suppose you have an ad on another website with this URL to your site:

http://mysite.net/index.html?utm_source=giganoshopper.com&utm_medium=referral&utm_campaign=Christmas+specials&description=Garden+gloves

In this URL, the key "description" delineates the content supplied in the URL for that campaign. (These terms and phrases appear under the Ad Content column in the Campaign detail page in the Traffic Sources report.) To use that key as your customized campaign content key, you would set:

Async Snippet (recommended)
_gaq.push(['_setCampContentKey', 'description']);

parameters

String   newCampContentKey New campaign content key to set.

_setCampMediumKey()

_setCampMediumKey(newCampMedKey)
Sets the campaign medium key, which is used to retrieve the medium from your campaign URLs. The medium appears as a segment option in the Campaigns report.

For example, suppose you have an ad on another website with this URL to your site:

http://mysite.net/index.html?utm_source=giganoshopper.com&method=ad&utm_campaign=Christmas+specials&utm_content=Garden+gloves


In this URL, the key "method" delineates the medium in the URL for that campaign.

Async Snippet (recommended)
_gaq.push(['_setCampMediumKey', 'method']);

parameters

String   newCampMedKey Campaign medium key to set.

_setCampNameKey()

_setCampNameKey(newCampNameKey)
Sets the campaign name key. The campaign name key is used to retrieve the name of your advertising campaign from your campaign URLs. You would use this function on any page that you want to track click-campaigns on.

For example, suppose you send an email to registered users about a special offer, and the link to that offer looks like:

http://mysite.net/index.html?utm_source=In+House&utm_medium=email&offer_type=Fall+email+offers


In this URL, the key "offer_type" delineates the name supplied in the URL for that campaign. (This is the name that appears in the list of Campaigns in the Traffic Sources report.)

Async Snippet (recommended)
_gaq.push(['_setCampNameKey', 'offer_type']);

parameters

String   newCampNameKey Campaign name key.

_setCampNOKey()

_setCampNOKey(newCampNOKey)
Sets the campaign no-override key variable, which is used to retrieve the campaign no-override value from the URL. By default, this variable and its value are not set. For campaign tracking and conversion measurement, this means that, by default, the most recent impression is the campaign that is credited in your conversion tracking. If you prefer to associate the first-most impressions to a conversion, you would set this method to a specific key, and in the situation where you use custom campaign variables, you would use this method to set the variable name for campaign overrides. The no-override value prevents the campaign data from being over-written by similarly-defined campaign URLs that the visitor might also click on.

If you have an ad on another website with this URL to your site:

http://mysite.net/index.html?utm_source=giganoshopper.com&utm_medium=referral&utm_campaign=Christmas+specials&utm_content=Garden+gloves&noo=1234


In this URL, the key "noo" delineates the no-override value in the URL for that campaign.

Async Snippet (recommended)
_gaq.push(['_setCampNOKey', 'noo']);

parameters

String   newCampNOKey Campaign no-override key to set.

_setCampSourceKey()

_setCampSourceKey(newCampSrcKey)
Sets the campaign source key, which is used to retrieve the campaign source from the URL. "Source" appears as a segment option in the Campaigns report.

For example, suppose you have an ad on another website with this URL to your site:

http://mysite.net/index.html?source=giganoshopper.com&utm_medium=referral&utm_campaign=Christmas+specials&utm_content=Garden+gloves


In this URL, the key "source" delineates the source in the URL for that campaign.

Async Snippet (recommended)
_gaq.push(['_setCampSourceKey', 'source']);

parameters

String   newCampSrcKey Campaign source key to set.

_setCampTermKey()

_setCampTermKey(newCampTermKey)
Sets the campaign term key, which is used to retrieve the campaign keywords from the URL.

For example, suppose you have a paid ad on a search engine tagged as follows:

http://mysite.net/index.html?source=weSearch4You.com&utm_medium=paidSearchAd&utm_campaign=Christmas+specials&utm_content=Garden+gloves&term=garden+tools


In this URL, the key "term" delineates the keyword terms in the URL for that campaign.

Async Snippet (recommended)
_gaq.push(['_setCampTermKey', 'term']);

parameters

String   newCampTermKey Term key to set.

_setCampaignTrack()

_setCampaignTrack(bool)
Sets the campaign tracking flag. By default, campaign tracking is set to true for standard Google Analytics set up. If you wish to disable campaign tracking and the associated cookies that are set for campaign tracking, you can use this method.

parameters

Boolean   true or false True by default, which enables campaign tracking. If set to false, campaign tracking is disabled.

_setCampaignCookieTimeout()

_setCampaignCookieTimeout(cookieTimeoutMillis)

Sets the campaign tracking cookie expiration time in milliseconds. By default, campaign tracking is set for 6 months. In this way, you can determine over a 6-month period whether visitors to your site convert based on a specific campaign. However, your business might have a longer or shorter campaign time-frame, so you can use this method to adjust the campaign tracking for that purpose.

You can change the expiration timeout to 0 to indicate that this cookie should be deleted when the browser is closed.

Async Snippet (recommended)
_gaq.push(['_setCampaignCookieTimeout', 15768000000]);

parameters

Number   cookieTimeoutMillis New cookie expiration time in milliseconds or 0 to delete the cookie when the browser is closed.

_setCookieTimeout()

_setCookieTimeout(newDefaultTimeout)
This method is deprecated. Please use _setCampaignCookieTimeout(cookieTimeoutMillis) instead.
Sets the campaign tracking cookie expiration time in seconds. By default, campaign tracking is set for 6 months. In this way, you can determine over a 6-month period whether visitors to your site convert based on a specific campaign. However, your business might have a longer or shorter campaign time-frame, so you can use this method to adjust the campaign tracking for that purpose.
Async Snippet (recommended)
_gaq.push(['_setCookieTimeout', 3152600]);

parameters

String   newDefaultTimeout New default cookie expiration time to set. Pass in as a string and it is converted to an integer.

_setReferrerOverride()

_setReferrerOverride(newReferrerUrl)
Sets the referrer URL used to determine campaign tracking values. Use this method to allow gadgets within an iFrame to track referrals correctly. By default, campaign tracking uses the document.referrer property to determine the referrer URL, which is passed in the utmr parameter of the GIF request. However, you can over-ride this parameter with your own value. For example, if you set the new referrer to http://www.google.com/search?hl=en&q=hats, the campaign cookie stores a new campaign with source=google, medium=organic, and keyword=hats.

parameters

String   newReferrerOverride The new url for the document referrer.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.