Measure single-page applications
In a single-page application (SPA), only a single HTML page is loaded and the content is then updated using JavaScript APIs to change the displayed content. These changes are not measured as new page views by default. It is therefore necessary to generate virtual page views for this.
There are two methods for measuring virtual page views:
Automatic wrapper function
Certain changes can be recognized automatically and used to trigger the measurement of a new page view. To do this, the following addition must be made to the etracker code integrated in the website:
data-page-changed-detection=<Modus>
These options are available for the mode:
- off: Off.
- url: Triggers a new page request if the URL changes without a hash value.
- url_debug: Like url, but can only be read in the console.log of the browser DevTools.
- hash: Triggers a new page request if the URL including the hash value changes.
- hash_debug: Like hash, but can only be read in the console.log of the browser DevTools.
- title: Triggers a new page call if document.title changes .
- title_debug: Like title, but can only be read in the console.log of the browser DevTools.
Manual installation of the wrapper
The wrapper is delivered with the standard JavaScript code from etracker and can be installed like this, for example:
<script>
function testCall(){
if(typeof(_etracker) === 'object') {
et_eC_Wrapper({et_et: 'ACCOUNTSCHLÜSSEL', et_pagename: 'pagename', et_areas: 'Bereich1/Bereich2/Bereich3', et_seg1: 'Eigenes Segment 1'});
}
}
</script>
To ensure that the call of the wrapper function does not lead to a JavaScript error due to any blocked etracker code, e.g. by excluding it from the count.
To ensure that calling the wrapper function does not lead to a JavaScript error due to any blocked etracker code, e.g. exclusion from counting, the presence of the etracker object is first checked with typeof
.
Parameters of the wrapper
The parameter et_et
for the account key is a mandatory parameter.
All other parameters are optional:
Variable | Type | Bedeutung | Beschreibung |
---|---|---|---|
et_pagename | String | Seitenname | Eindeutiger Name der Seite |
et_areas | String | Bereichsname | Bezeichnung des Seitenbereichs |
et_tval | Float | Gesamtbestellwert | Netto Umsatz, der durch die Zielerreichung generiert wurde |
et_tonr | String | Bestellnummer | Eindeutige Bestellnummer (ohne Kommas und Semikolons) |
et_tsale | Integer | Bestellstatus | Bestellstatus für Umsatzziele: 0 = Lead 1 = Sale 2 = Vollstorno |
et_basket | String | Warenkorb | Vom Shopsystem vergebene Parameter zum Zuordnen der Warenkorbartikel (ArtNr,ArtName,ArtGruppe,Anzahl,Preis) |
cc_attributes | String | Kampagnen-Attribute | Attributname und Attributwert für Kampagnen |
et_seg1 | String | Eigenes Segment | Inhalt des eigenen Segments |
If the optional parameters are not explicitly set, the values that were transmitted to etracker the last time the page was accessed are used. The values can be transmitted via the standard tracking code when the page is called up in the browser or via the wrapper when the page is loaded dynamically.
The following call generates the same data as the original call via the standard tracking code:
<script>
if(typeof(_etracker) === 'object') {
et_eC_Wrapper({et_et: 'ACCOUNTSCHLÜSSEL'});
}
</script>
<script>
if(typeof(_etracker) === 'object') {
et_eC_Wrapper(
{
et_et: 'ACCOUNTSCHLÜSSEL',
et_pagename:'Suchergebnisse',
et_areas: 'DE/Suche',
cc_attributes:{etcc_cu:'onsite',etcc_med_onsite:'Interne Suche',etcc_cmp_onsite:'Mit Ergebnis',etcc_st_onsite:'Stiefel'},
et_seg1: 'eingeloggt',
et_seg2: 'B2B'
}
);
}
</script>
General notes on the wrapper function
Recording events in interaction with the wrapper
If events are transmitted to etracker as part of etracker event tracking, they are assigned to the page name that was last transmitted to etracker before the event was triggered. If, for example For example, if a page view was first triggered using a wrapper and then an event was tracked, the event is assigned in the evaluation to the page name that was transmitted to etracker with the wrapper.
Capturing URLs in interaction with the wrapper
Since no URL can be transmitted to etracker via the wrapper, etracker always assigns the page views that are transmitted to etracker via the wrapper to the URL that is stored in the document.location.href
property.
A unique URL is not available for the evaluation of SPAs. However, in order to ensure a clear evaluation of the individual contents, particular care should be taken to ensure that each virtual page is given a unique page name that is easy to understand in the evaluation.
If this is not possible due to the large amount of content or for other reasons, we recommend that you do not use speaking page names, but instead transmit virtual page paths via the parameter et_pagename
.