-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔨 refactor sentry frontend scripts to use secureRenderer
- Loading branch information
1 parent
b4fd7e1
commit df125fa
Showing
3 changed files
with
136 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php /** @var \JustBetter\Sentry\Block\SentryScript $block */ ?> | ||
|
||
|
||
<?php if ($block->useLogRocketIdentify()): ?> | ||
|
||
define('customerData', | ||
['jquery', 'Magento_Customer/js/customer-data'], | ||
function ($, customerData) { | ||
'use strict'; | ||
|
||
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; | ||
}; | ||
|
||
} | ||
); | ||
|
||
require(["customerData"], function (customerData) { | ||
|
||
customerData().then(function (loggedIn, data) { | ||
if (!loggedIn) { | ||
return; | ||
} | ||
|
||
LogRocket.identify(data.websiteId, { | ||
name: data.fullname, | ||
email: data.email | ||
}); | ||
|
||
}); | ||
}); | ||
|
||
|
||
<?php endif; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php /** @var \JustBetter\Sentry\Block\SentryScript $block */ ?> | ||
if (typeof Sentry !== 'undefined') { | ||
Sentry.init({ | ||
dsn: '<?= $block->escapeUrl(trim($block->getDSN())) ?>', | ||
release: '<?= $block->escapeHtml(trim($block->getVersion())) ?>', | ||
environment: '<?= $block->escapeHtml(trim($block->getEnvironment())) ?>', | ||
integrations: [ | ||
<?php if ($block->isTracingEnabled()): ?> | ||
Sentry.browserTracingIntegration({ | ||
enableInp: true, | ||
}), | ||
<?php endif ?> | ||
<?php if ($block->useSessionReplay()): ?> | ||
Sentry.replayIntegration({ | ||
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; ?> | ||
}); | ||
} |