Prints the tracking script of the Google Analytics visitor tracking service.

Kuvaus

The content of this tag belongs to the content printed by the {Extensions} tag.

You should use the {GoogleAnalyticsScript} tag only if you'd like to e.g. use an account other than the one saved in the extension's settings. In such case, add the tag to your theme before the {Extensions} tag to a page's <head> part.

If a new version of the tracking script is enabled, add the for:'head' attribute to the tag.

If you use asynchronous tracking, use the tag in the <body> element with the attribute for:'body'.

Syntaksi

{GoogleAnalyticsScript( exclude: string, for: string, account: string, setdomainname: string, setallowlinker: boolean )}

Näkyvyys

Toimii näkyvyydessä: globaali

It is possible to use global visibility tags in any page template and within any tag.

The {GoogleAnalyticsScript} tag is usually used only in a page's <head> element.

Using asynchronous tracking

If the Google Analytics asynchronous tracking is enabled in your online store, the {GoogleAnalyticsScript} tag is required in a page's <body> element:

 ... {GoogleAnalyticsScript( for: 'body' )} </body>

In such case, use the tag with the for: 'body' attribute.

Using multiple Google Analytics accounts in an online store

In this example, we assume that different store versions use the same store theme.

To track traffic in different store versions by using Google Analytics, you'll need a separate tracking script file for each version:

{GoogleAnalyticsScript( account: 'UA-12345678-1' )}

The {GoogleAnalyticsScript} tag's account attribute specifies the Analytics account through which the version's traffic is to be tracked.

Name each file according to the convention ga-script-n.html, where n stands for the version's ID number. Version ID can be found in a browser's address bar when the version is opened for editing in the admin panel.

The tracking file can be fetched to the theme by using the {Helper} tag.fi

 ... {Helper( file: 'helpers/ga-script-{VersionID}' )} {Extensions(for: 'head')} </head>

The {VersionID} tag is used to retrieve a tracking file that corresponds to the version currently selected by the customer. Make sure to retrieve the tracking script before the {Extensions} tag.

If the versions use different themes, add to each theme's <head> element the same markup that was added to the tracking files in this example.

Attribuutit

exclude:

The value 'schema' removes the default Schema.org markup from the page.

Sallitut arvot:
  • 'schema'
for:

Defines the element inside of which the tracking script should be printed.

Allowed values:

  • 'head': the content is printed in the <head> element; required with newer tracking scripts
  • 'body': the content is printed in the <body> element; used with the asynchronous tracking
account:

Defines the Google account whose tracking script should be printed.

Allowed values: string

Set the attribute value to the account tracking code, for example, 'UA-52255336-1'.

setdomainname:

Defines the domain that is the source of traffic that should be tracked.

The attribute is not available with Google's Universal Analytics tracking script.

Allowed values:

  • 'auto': the domain is defined based on the DOM's document.domain value
  • 'none': any domain's traffic is tracked
  • You can also use a value such as the {ShopUrl} tag if you want to always track traffic from only one domain.

The tag serves the same purpose as Google's _setDomainName() function.

setallowlinker:

Defines whether to track traffic from multiple domains.

The attribute is not available with Google's Universal Analytics tracking script.

This attribute can be used to make Analytics track two connected pages as a single tracking item, even if the pages have different domains (cross-domain tracking).

Allowed values: true/false. Default value: true.

To prevent tracking from multiple domains, use the value false.

The tag serves the same purpose as Google's _setAllowLinker() function.

before/after:

With the before and after attributes, you can define content that is output before or after the content produced by the tag.

Allowed values: text that may contain HTML and Interface markup.

E.g.

  • before: '<p>This markup appears before the tag's own content.</p>'.
  • after: '<p>This appears after the tag's own content.</p>'

If the tag does not produce any content, the content of the before and after attributes will also not be displayed.

escape:

Adds an escape character before quotation marks in the output. The attribute makes it easier to process the tag-produced content when using JavaScript.

Allowed values: true/false. The default value is false.

or:

Defines alternative content that is displayed if the tag itself does not produce any content.

Allowed values: text that may contain HTML and Interface markup.

E.g. or:'Content not found.'