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

Description

This tag's content 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'.

See also the instructions on how to deploy and use Google Analytics in MyCashflow.

Syntax

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

Scope

Required scope: globaali

Tags with global scope can be used on any template and in 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'
)}

In the {GoogleAnalyticsScript} tag's account attribute, you can define the Analytics account that should be used for tracking a version's traffic.

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 fetches the tracking file that corresponds to the version selected by a customer. Make sure to fetch 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.

Allowed values:
  • '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

Indicate the account's tracking code as the attribute's value, e.g. 'UA-52255336-1'.

setdomainname:

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

The attribute is not in use 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
  • To track traffic only from one domain at any given time, you can use e.g. the {ShopUrl} tag as the attribute's value.

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

setallowlinker:

Defines whether to track traffic from multiple domains.

The attribute is not in use 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. The default value is true.

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

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

after/before:

By using the after and before attributes you can define content that is output either after or before the tag's output.

Allowed values:The HTML and Interface markup

E.g.

  • before: '<p>Tämä merkkaus näkyy ennen tagin omaa sisältöä.</p>'
  • after: '<p>Tämä taas näkyy tagin oman sisällön jälkeen.</p>'

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

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:The HTML and Interface markup

E.g. or:'Sisältöä ei löytynyt.'