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 {
|
||||
static values = {
|
||||
url: String,
|
||||
title: String,
|
||||
userInfo: String
|
||||
payload: Object
|
||||
};
|
||||
|
||||
connect() {
|
||||
if (typeof window.dataLayer !== 'undefined') {
|
||||
window.dataLayer.push({
|
||||
'event': 'VirtualPageview',
|
||||
'virtualPageURL': this.urlValue,
|
||||
'virtualPageTitle': this.titleValue,
|
||||
'userInfo': this.userInfoValue
|
||||
});
|
||||
window.dataLayer.push(this.payloadValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<div {{ stimulus_controller('data-layer', {
|
||||
'url': url,
|
||||
'title': title,
|
||||
'payload': {
|
||||
'event': 'VirtualPageview',
|
||||
'virtualPageURL': url,
|
||||
'virtualPageTitle': title,
|
||||
'userInfo': is_granted('ROLE_USER') ? 'mitglied' : 'gast'
|
||||
}
|
||||
}) }}></div>
|
||||
|
||||
@@ -59,22 +59,18 @@
|
||||
|
||||
{% block data_layer %}
|
||||
{% if bookingTotal is not null and travelName is not null %}
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
var consent = (window.CookieFirst && window.CookieFirst.consent) || { advertising: false };
|
||||
if (consent.advertising) {
|
||||
dataLayer.push({
|
||||
<div {{ stimulus_controller('data-layer', {
|
||||
'payload': {
|
||||
'event': 'Transaction',
|
||||
'userInfo': '{{ is_granted('ROLE_USER') ? 'mitglied' : 'gast' }}',
|
||||
'transactionId': '{{ bookingNumber }}',
|
||||
'transactionTotal': {{ bookingTotal }},
|
||||
'userInfo': is_granted('ROLE_USER') ? 'mitglied' : 'gast',
|
||||
'transactionId': bookingNumber,
|
||||
'transactionTotal': bookingTotal,
|
||||
'transactionProducts': [{
|
||||
'name': '{{ travelName|e('js') }}',
|
||||
'price': {{ bookingTotal }},
|
||||
'name': travelName,
|
||||
'price': bookingTotal,
|
||||
'quantity': 1
|
||||
}]
|
||||
});
|
||||
}
|
||||
</script>
|
||||
}) }}></div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user