Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
d866d795
Unverified
Commit
d866d795
authored
May 28, 2021
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: anonymize outbound link events sent to google analytics
fixes
https://github.com/Uniswap/uniswap-interface/issues/1729
parent
7f1def30
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
36 deletions
+48
-36
components.tsx
src/theme/components.tsx
+48
-36
No files found.
src/theme/components.tsx
View file @
d866d795
...
...
@@ -197,6 +197,52 @@ export const UniTokenAnimated = styled.img`
filter
:
drop
-
shadow
(
0
px
2
px
4
px
rgba
(
0
,
0
,
0
,
0.15
));
`
const ETHERSCAN_HOSTNAMES: { [hostname: string]: true } = {
'etherscan.io': true,
'ropsten.etherscan.io': true,
'rinkeby.etherscan.io': true,
'kovan.etherscan.io': true,
'goerli.etherscan.io': true,
}
/**
* Returns the anonymized version of the given href, i.e. one that does not leak user information
* @param href the anonymized version of the given href
*/
function anonymizeLink(href: string): string {
try {
const url = new URL(href)
if (ETHERSCAN_HOSTNAMES[url.hostname]) {
return `
$
{
url
.
hostname
}
/${url.pathname.split
(
'/
'
)[1]}/***`
}
return href
} catch (error) {
console.error(
'
Failed
to
anonymize
outbound
link
'
, error)
return href
}
}
function useHandleClickLinkCallback() {
return useCallback((event: React.MouseEvent<HTMLAnchorElement>) => {
const { target, href } = event.currentTarget
const anonymizedHref = anonymizeLink(href)
// don
'
t
prevent
default
,
don
'
t redirect if it
'
s
a
new
tab
if
(
target
===
'
_blank
'
||
event
.
ctrlKey
||
event
.
metaKey
)
{
ReactGA
.
outboundLink
({
label
:
anonymizedHref
},
()
=>
{
console
.
debug
(
'
Fired outbound link event
'
,
anonymizedHref
)
})
}
else
{
event
.
preventDefault
()
// send a ReactGA event and then trigger a location change
ReactGA
.
outboundLink
({
label
:
anonymizedHref
},
()
=>
{
window
.
location
.
href
=
anonymizedHref
})
}
},
[])
}
/**
* Outbound link that handles firing google analytics events
*/
...
...
@@ -206,24 +252,7 @@ export function ExternalLink({
rel
=
'
noopener noreferrer
'
,
...
rest
}:
Omit
<
HTMLProps
<
HTMLAnchorElement
>
,
'
as
'
|
'
ref
'
|
'
onClick
'
>
&
{
href
:
string
})
{
const handleClick = useCallback(
(event: React.MouseEvent<HTMLAnchorElement>) => {
// don't prevent default, don't redirect if it's a new tab
if (target === '_blank' || event.ctrlKey || event.metaKey) {
ReactGA.outboundLink({ label: href }, () => {
console.debug('Fired outbound link event', href)
})
} else {
event.preventDefault()
// send a ReactGA event and then trigger a location change
ReactGA.outboundLink({ label: href }, () => {
window.location.href = href
})
}
},
[href, target]
)
return <StyledLink target={target} rel={rel} href={href} onClick={handleClick} {...rest} />
return
<
StyledLink
target=
{
target
}
rel=
{
rel
}
href=
{
href
}
onClick=
{
useHandleClickLinkCallback
()
}
{
...
rest
}
/>
}
export
function
ExternalLinkIcon
({
...
...
@@ -232,25 +261,8 @@ export function ExternalLinkIcon({
rel
=
'
noopener noreferrer
'
,
...
rest
}:
Omit
<
HTMLProps
<
HTMLAnchorElement
>
,
'
as
'
|
'
ref
'
|
'
onClick
'
>
&
{
href
:
string
})
{
const handleClick = useCallback(
(event: React.MouseEvent<HTMLAnchorElement>) => {
// don't prevent default, don't redirect if it's a new tab
if (target === '_blank' || event.ctrlKey || event.metaKey) {
ReactGA.outboundLink({ label: href }, () => {
console.debug('Fired outbound link event', href)
})
} else {
event.preventDefault()
// send a ReactGA event and then trigger a location change
ReactGA.outboundLink({ label: href }, () => {
window.location.href = href
})
}
},
[href, target]
)
return
(
<LinkIconWrapper target={target} rel={rel} href={href} onClick={
handleClick
} {...rest}>
<
LinkIconWrapper
target=
{
target
}
rel=
{
rel
}
href=
{
href
}
onClick=
{
useHandleClickLinkCallback
()
}
{
...
rest
}
>
<
LinkIcon
/>
</
LinkIconWrapper
>
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment