-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from TokenScript/jf/analytics
Setup BC analytics to collect data for Salesforce integration demo
- Loading branch information
Showing
12 changed files
with
268 additions
and
3 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
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 |
---|---|---|
|
@@ -5,3 +5,6 @@ BASE_PATH=/ | |
MC_API_URL= | ||
MC_API_KEY= | ||
MC_LIST_ID= | ||
|
||
ANALYTICS_URL= | ||
ANALYTICS_JWT= |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,67 @@ | ||
import Analytics from '@tokenscript/analytics-client'; | ||
|
||
const analyticsUrl = process.env.ANALYTICS_URL; | ||
const jwtToken = process.env.ANALYTICS_JWT; | ||
|
||
const analyticsClient = new Analytics(analyticsUrl, jwtToken).client; | ||
|
||
// TODO: all the following event reporting functions can be replaced | ||
// with `Analytics.connectTokenNegotiator` once TN supports multiple event hooks | ||
export function sendWalletConnectedEvent({ | ||
providerType, | ||
blockchain, | ||
chainId, | ||
address, | ||
}) { | ||
analyticsClient.event({ | ||
name: 'wallet-connected', | ||
eventProperties: { | ||
provider_type: providerType, | ||
blockchain, | ||
chain_id: chainId, | ||
address, | ||
}, | ||
}); | ||
} | ||
|
||
export function sendTokensSelectedEvent({ selectedTokens }) { | ||
const eventProperties = Object.fromEntries( | ||
Object.entries(selectedTokens).map(([collectionId, { tokens }]) => [ | ||
collectionId, | ||
tokens.map((token) => token.ticketIdNumber ?? token.tokenId), | ||
]) | ||
); | ||
|
||
analyticsClient.event({ | ||
name: 'token-selected', | ||
eventProperties, | ||
}); | ||
} | ||
|
||
export function sendTokenProofEvent({ | ||
data: { address, messageToSign, signature }, | ||
error, | ||
}) { | ||
const eventProperties = error | ||
? { error } | ||
: { | ||
address, | ||
messageToSign, | ||
signature, | ||
}; | ||
|
||
analyticsClient.event({ | ||
name: 'token-proof', | ||
eventProperties, | ||
}); | ||
} | ||
|
||
const AGREE_TO_STATS_KEY = 'bc-agree-stats'; | ||
|
||
export function loadAgreeToStats() { | ||
return localStorage.getItem(AGREE_TO_STATS_KEY) === 'true'; | ||
} | ||
|
||
export function storeAgreeToStats(value) { | ||
localStorage.setItem(AGREE_TO_STATS_KEY, value); | ||
} |
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
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
8 changes: 8 additions & 0 deletions
8
ecommerce-store-website/src/ui/sections/stats-disclaimer/index.js
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,8 @@ | ||
|
||
|
||
// | ||
// Brand Connector Demo / UI / Sections / Stats Disclaimer | ||
// | ||
|
||
|
||
export { default } from './stats-disclaimer'; |
39 changes: 39 additions & 0 deletions
39
ecommerce-store-website/src/ui/sections/stats-disclaimer/stats-disclaimer.js
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,39 @@ | ||
|
||
|
||
// Dependencies | ||
import React, { useContext } from 'react'; | ||
import clsx from 'clsx'; | ||
|
||
// App | ||
import { TokenContext } from 'src/providers/TokenContextProvider'; | ||
import { Button } from 'ui/components'; | ||
|
||
// Styles | ||
import styles from "./stats-disclaimer.module.scss"; | ||
|
||
|
||
// | ||
// Brand Connector Demo / UI / Sections / Stats Disclaimer | ||
// | ||
|
||
|
||
export default function StatsDisclaimer() { | ||
const { agreeToStats, setAgreeToStats } = useContext(TokenContext); | ||
|
||
const handleOnClick = () => { | ||
setAgreeToStats(true); | ||
}; | ||
|
||
return !agreeToStats && ( | ||
<div className={ styles[ 's-stats-disclaimer' ] }> | ||
<span className={ styles[ 's-stats-disclaimer_desc' ] }> | ||
This page collect data for analytics purposes. | ||
</span> | ||
<Button | ||
className={ clsx( styles[ 's-stats-disclaimer_button' ], '-style-light-outline' ) } | ||
onClick={handleOnClick}> | ||
Agree | ||
</Button> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.