fix: streamline datalayer integration for all events
This commit is contained in:
@@ -2,19 +2,12 @@ import { Controller } from '@hotwired/stimulus';
|
|||||||
|
|
||||||
export default class extends Controller {
|
export default class extends Controller {
|
||||||
static values = {
|
static values = {
|
||||||
url: String,
|
payload: Object
|
||||||
title: String,
|
|
||||||
userInfo: String
|
|
||||||
};
|
};
|
||||||
|
|
||||||
connect() {
|
connect() {
|
||||||
if (typeof window.dataLayer !== 'undefined') {
|
if (typeof window.dataLayer !== 'undefined') {
|
||||||
window.dataLayer.push({
|
window.dataLayer.push(this.payloadValue);
|
||||||
'event': 'VirtualPageview',
|
|
||||||
'virtualPageURL': this.urlValue,
|
|
||||||
'virtualPageTitle': this.titleValue,
|
|
||||||
'userInfo': this.userInfoValue
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
<div {{ stimulus_controller('data-layer', {
|
<div {{ stimulus_controller('data-layer', {
|
||||||
'url': url,
|
'payload': {
|
||||||
'title': title,
|
'event': 'VirtualPageview',
|
||||||
'userInfo': is_granted('ROLE_USER') ? 'mitglied' : 'gast'
|
'virtualPageURL': url,
|
||||||
|
'virtualPageTitle': title,
|
||||||
|
'userInfo': is_granted('ROLE_USER') ? 'mitglied' : 'gast'
|
||||||
|
}
|
||||||
}) }}></div>
|
}) }}></div>
|
||||||
|
|||||||
@@ -59,22 +59,18 @@
|
|||||||
|
|
||||||
{% block data_layer %}
|
{% block data_layer %}
|
||||||
{% if bookingTotal is not null and travelName is not null %}
|
{% if bookingTotal is not null and travelName is not null %}
|
||||||
<script>
|
<div {{ stimulus_controller('data-layer', {
|
||||||
window.dataLayer = window.dataLayer || [];
|
'payload': {
|
||||||
var consent = (window.CookieFirst && window.CookieFirst.consent) || { advertising: false };
|
'event': 'Transaction',
|
||||||
if (consent.advertising) {
|
'userInfo': is_granted('ROLE_USER') ? 'mitglied' : 'gast',
|
||||||
dataLayer.push({
|
'transactionId': bookingNumber,
|
||||||
'event': 'Transaction',
|
'transactionTotal': bookingTotal,
|
||||||
'userInfo': '{{ is_granted('ROLE_USER') ? 'mitglied' : 'gast' }}',
|
'transactionProducts': [{
|
||||||
'transactionId': '{{ bookingNumber }}',
|
'name': travelName,
|
||||||
'transactionTotal': {{ bookingTotal }},
|
'price': bookingTotal,
|
||||||
'transactionProducts': [{
|
'quantity': 1
|
||||||
'name': '{{ travelName|e('js') }}',
|
}]
|
||||||
'price': {{ bookingTotal }},
|
|
||||||
'quantity': 1
|
|
||||||
}]
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
</script>
|
}) }}></div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user