Developers » AS2 tagging » JavaScript » Getting started » Tracker initialisation
Tracker initialisation
Foreword
Before starting, please download our JavaScript library, or push it onto our CDN, from within the Tag Composer interface.
This library enables you to:
- Set up your tagging perimeter/scope (site, domain used to write cookies, etc.).
- Select desired features via configurable plugins.
Once the library is set up, you must call it inside the <head>
of your page.
<!-- Local file --> <script src="smarttag.js"></script> <!-- CDN file --> <!-- File must be published on the TDN for this site within Tag Composer --> <script src="//tag.aticdn.net/YOURSITEID/smarttag.js"></script>
Initialisation
Tracker initialisation is done via JavaScript methods to be inserted.
<html> <head lang="en"> <meta charset="UTF-8"> <title>My Page</title> <script src="smarttag.js"></script> </head> <body> ... <script type="text/javascript"> var tag = new ATInternet.Tracker.Tag(); </script> </body> </html>
The constructor ATInternet.Tracker.Tag() can take two arguments, a first one intended for overload Tracker configuration and a second intended for add context values.
Configuration
The file “smarttag.js” contains the default configuration defined during generation in Tag Composer. It’s possible to overload a part of the configuration by specifying the new settings during initialisation.
Example:
var tag = new ATInternet.Tracker.Tag({secure: true});
Here, the “secure” setup variable was force-set to true.
List of basic setup variables that can be overloaded:
- The
secure
variable enables the sending of information in a secure manner, or not. Specify true in the case of an HTTPS protocol, and false for an HTTP protocol. - The
disableCookie
variable, if set to true, enables you to block the writing of tracker cookies (first and third). - The
cookieDomain
variable enables you to specify the domain for the writing of cookies. In cases where this parameter is empty (cookieDomain: ''
), the domain of the current page will be used.
- The
cookieSecure
variable, if set to true, enables you to add the option ‘secure’ for the writing of tracker cookies (first). Please be aware that ‘secure’ cookies will only work on HTTPS pages. - The
ignoreEmptyChapterValue
variable, if set to true, enables you to ignore chapters without value.
>= 5.5.0
Other setup variables exist, but require advanced knowledge of the Tracker (see Appendix).
Context
Its also possible to force context values which will be added and shared between tags according to the type.
Example :
var tag = new ATInternet.Tracker.Tag({}, {'forcedCampaign': 'campaignValue'});
Here, the campaign value defined in “forcedCampaign” will be added in page tags.
List of context variables that can be declared :
- The
forcedCampaign
enables you to declare and force a campaign. - The
forcedReferer
variable enables you to declare and force a referer.
Basic tag
Here is an example of a tag allowing you to measure a pageview with the label “Page Name”:
<script type="text/javascript"> var ATTag = new ATInternet.Tracker.Tag(); ATTag.page.send({name:'Page_Name'}); </script>
Appendix
Setup variables that can be overloaded:
Name | Default value | Description | Version |
---|---|---|---|
secure | false | Force the sending of information in a secure manner (HTTPS) | < 5.19.0 |
disableCookie | false | Enables you to block the writing of tracker cookies (first and third) | – |
cookieDomain | TagComposer value | Domain for the writing of cookies. If this parameter is empty (cookieDomain: '' ), the domain of the current page will be used | – |
cookieSecure | false | Add option ‘secure’ for the writing of tracker cookies (first) | >= 5.5.0 |
ignoreEmptyChapterValue | true | Ignore chapters without value | >= 5.5.0 |
site | TagComposer value | Site number | – |
log | TagComposer value | Subdomain of the collector AT Internet. Deprecated since 5.13.0, see collectDomain | < 5.13.0 |
logSSL | TagComposer value | subdomain of the secured (HTTPS) collector AT Internet. Deprecated since 5.13.0, see collectDomain | < 5.13.0 |
domain | TagComposer value | Domain of URL hits. Deprecated since 5.13.0, see collectDomain | < 5.13.0 |
pixelPath | /hit.xiti | Path toward the pixel file for hits | – |
preview | false | Force the sending of page hits in cases of loads in preview mode on the Safari browser (true: measurement enabled, false: measurement disabled) | – |
collectDomain | TagComposer value | Data collection domain | >= 5.13.0 |
collectDomainSSL | TagComposer value | Secured data collection domain | >= 5.13.0 |
sendHitWhenOptOut | TagComposer value | Allows sending anonymous hits when the user is in “OPT-OUT” mode (first party) | >= 5.14.0 |
forceHttp | false | Force hits being sent over HTTP. Since 5.19.0, hits are automatically sent over HTTPS. Requires client side visitor ID (server-side cookies require HTTPS). | >= 5.19.0 |
maxHitSize | 2000 | Maximum characters allowed per hit. Over that number, hit will be cut in multiple parts (multi-hits) | >= 5.19.0 |
requestMethod | GET | HTTP method used to send hits. ‘GET’ or ‘POST’ | >= 5.19.0 |
urlPropertyAuto | TagComposer value | If enabled, automatically add a property containing the URL of the page. | >= 5.27.0 |
urlPropertyQueryString | TagComposer value | If enabled and urlPropertyAuto enabled, add the Querystring to the property containing the URL of the page | >= 5.27.0 |
sameSiteStrict | false | If enabled, add the flag SameSite=Strict to client-side cookies | >=5.28.2 |