-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhyva-themes-magento2-justbetter-sentry-updated-sentry-script.patch
175 lines (165 loc) · 6.51 KB
/
hyva-themes-magento2-justbetter-sentry-updated-sentry-script.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
diff --git a/src/view/frontend/templates/script/sentry.phtml b/src/view/frontend/templates/script/sentry.phtml
index 50575c3..b5b8adb 100755
--- a/src/view/frontend/templates/script/sentry.phtml
+++ b/src/view/frontend/templates/script/sentry.phtml
@@ -1,23 +1,84 @@
<?php
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis
-/** @var Escaper $escaper */
-/** @var SentryScript $block */
-
-use JustBetter\Sentry\Block\SentryScript;
-use Magento\Framework\Escaper;
+/** @var \JustBetter\Sentry\Block\SentryScript $block */
if (!$block->canUseScriptTag($block->getNameInLayout())) {
return;
}
+
+$bundleFile = 'bundle';
+
+if ($block->isTracingEnabled()) {
+ $bundleFile .= '.tracing';
+}
+
+if ($block->useSessionReplay()) {
+ $bundleFile .= '.replay';
+}
+
+$bundleFile .= '.min.js';
+
+$remoteFile = sprintf(
+ 'https://browser.sentry-cdn.com/%s/%s',
+ $block->escapeHtmlAttr($block->getJsSdkVersion()),
+ $bundleFile
+);
?>
-<script src="https://browser.sentry-cdn.com/<?= SentryScript::CURRENT_VERSION;?>/bundle.min.js"
- crossorigin="anonymous">
-</script>
+
+<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Promise" crossorigin></script>
+<script src="<?= /** @noEscape */$remoteFile ?>" crossorigin="anonymous"></script>
<script>
Sentry.init({
- dsn: '<?= $escaper->escapeUrl(trim($block->getDSN())) ?>',
- release: '<?= $escaper->escapeHtml(trim($block->getVersion())) ?>',
- environment: '<?= $escaper->escapeHtml(trim($block->getEnvironment())) ?>',
+ dsn: '<?= $block->escapeUrl(trim($block->getDSN())) ?>',
+ release: '<?= $block->escapeHtml(trim($block->getVersion())) ?>',
+ environment: '<?= $block->escapeHtml(trim($block->getEnvironment())) ?>',
+ integrations: [
+ <?php if ($block->isTracingEnabled()): ?>
+ new Sentry.BrowserTracing(),
+ <?php endif ?>
+ <?php if ($block->useSessionReplay()): ?>
+ new Sentry.Replay({
+ blockAllMedia: <?= $block->escapeHtml($block->getReplayBlockMedia() ? 'true' : 'false') ?>,
+ maskAllText: <?= $block->escapeHtml($block->getReplayMaskText() ? 'true' : 'false') ?>,
+ })
+ <?php endif ?>
+ ],
+ <?php if ($block->isTracingEnabled()): ?>
+ tracesSampleRate: <?= $block->escapeHtml($block->getTracingSampleRate()) ?>,
+ <?php endif ?>
+ <?php if ($block->useSessionReplay()): ?>
+ replaysSessionSampleRate: <?= $block->escapeHtml($block->getReplaySessionSampleRate()) ?>,
+ replaysOnErrorSampleRate: <?= $block->escapeHtml($block->getReplayErrorSampleRate()) ?>,
+ <?php endif ?>
+ ignoreErrors: <?= /** @noEscape */ $block->getIgnoreJsErrors() ?>,
+ <?php if ($block->stripStaticContentVersion() || $block->stripStoreCode()): ?>
+ beforeSend: function(event) {
+ event.exception.values.map(function (value) {
+ if (value.stacktrace === undefined || ! value.stacktrace) {
+ return value;
+ }
+
+ <?php if ($block->stripStaticContentVersion()): ?>
+ value.stacktrace.frames.map(function (frame) {
+ frame.filename = frame.filename.replace(/version[0-9]{10}\//, '');
+ return frame;
+ });
+ <?php endif; ?>
+
+ <?php if ($block->stripStoreCode()): ?>
+ value.stacktrace.frames.map(function (frame) {
+ <?php // phpcs:disable Generic.Files.LineLength ?>
+ frame.filename = frame.filename.replace('/<?= $block->escapeHtml($block->getStoreCode()); ?>/', '/');
+ <?php // phpcs:enable Generic.Files.LineLength ?>
+ return frame;
+ });
+ <?php endif; ?>
+
+ return value;
+ });
+ return event;
+ }
+ <?php endif; ?>
});
</script>
@@ -35,27 +96,59 @@ if (!$block->canUseScriptTag($block->getNameInLayout())) {
<?php if ($block->useLogRocketIdentify()): ?>
- const logRocketCustomerLoaded = function (event) {
+ define('customerData',
+ ['jquery', 'Magento_Customer/js/customer-data'],
+ function ($, customerData) {
+ 'use strict';
- const sectionData = event.detail.data;
+ var getCustomerInfo = function () {
+ var customer = customerData.get('customer');
+
+ return customer();
+ };
+
+ var isLoggedIn = function (customerInfo) {
+ return customerInfo && customerInfo.firstname;
+ };
+
+ return function () {
+ var deferred = $.Deferred();
+ var customerInfo = getCustomerInfo();
+
+ if (customerInfo && customerInfo.data_id) {
+ deferred.resolve(isLoggedIn(customerInfo), customerInfo);
+ } else {
+ customerData.reload(['customer'], false)
+ .done(function () {
+ customerInfo = getCustomerInfo()
+ deferred.resolve(isLoggedIn(customerInfo), customerInfo);
+ })
+ .fail(function () {
+ deferred.reject();
+ });
+ }
+
+ return deferred;
+ };
- if (!sectionData) {
- return; // no section data
- }
- const customer = sectionData.customer;
- if (!customer || !customer.firstname ){
- return; // not logged in
}
+ );
- LogRocket.identify(customer.websiteId, {
- name: customer.fullname,
- email: customer.email
- });
+ require(["customerData"], function (customerData) {
- window.removeEventListener("private-content-loaded", logRocketCustomerLoaded);
- }
+ customerData().then(function (loggedIn, data) {
+ if (!loggedIn) {
+ return;
+ }
+
+ LogRocket.identify(data.websiteId, {
+ name: data.fullname,
+ email: data.email
+ });
+
+ });
+ });
- window.addEventListener("private-content-loaded", logRocketCustomerLoaded);
<?php endif; ?>
</script>