Skip to content

Commit

Permalink
fix: add click tracking + random number (#1758)
Browse files Browse the repository at this point in the history
  • Loading branch information
dennyscode authored Feb 12, 2025
1 parent dfec539 commit d29f7b1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/components/FeatureCards/FeatureCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ export const FeatureCard = ({ data }: FeatureCardProps) => {
theme.palette.white.main,
]);

useEffect(() => {
if (isSpindlTrackData(data.attributes)) {
trackSpindl(
'impression',
data.attributes.spindlData.impression_id,
data.attributes.spindlData.ad_creative_id,
);
}
// allow spindl data to be tracked once
}, [data.attributes]);

useEffect(() => {
if (!eventFired.current && open) {
trackEvent({
Expand Down Expand Up @@ -121,6 +132,7 @@ export const FeatureCard = ({ data }: FeatureCardProps) => {
return;
}
trackSpindl(
'click',
attributes.spindlData.impression_id,
attributes.spindlData.ad_creative_id,
);
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/feature-cards/spindl/trackSpindl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ interface ImpressionPayload {
const SPINDLE_TRACKING_PATH = '/external/track';

export async function trackSpindl(
type: string,
impressionId: string,
adCreativeId: string,
): Promise<void> {
const spindlConfig = getSpindlConfig();

const payload: ImpressionPayload = {
type: 'impression',
type,
placement_id: 'notify_message',
impression_id: impressionId,
ad_creative_id: adCreativeId,
Expand Down
18 changes: 16 additions & 2 deletions src/hooks/feature-cards/spindl/useSpindlCards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@ export const useSpindlCards = () => {
const spindlConfig = getSpindlConfig();
const { fetchData } = useCallRequest();

// Feature Flag logic: Show Spindl for ~25% of users
const showSpindle = Math.random() < 0.25;

const fetchSpindlData = useCallback(
async ({ country, chainId, tokenAddress, address }: SpindlFetchParams) => {
if (!showSpindle) {
// console.log('User is not part of the Spindl A/B test group.');
return; // Exit early if the user is not in the A/B test group
}

const locale = getLocale().split('-');
const queryParams: Record<string, string | undefined> = {
placement_id: 'notify_message',
limit: '1',
limit: '3',
address,
country: country || locale[1],
chain_id: chainId?.toString(),
Expand All @@ -57,7 +65,13 @@ export const useSpindlCards = () => {
console.error('Error fetching Spindl data:', error);
}
},
[fetchData, processSpindlData, spindlConfig.apiUrl, spindlConfig.headers],
[
fetchData,
processSpindlData,
spindlConfig.apiUrl,
spindlConfig.headers,
showSpindle,
],
);

useEffect(() => {
Expand Down

0 comments on commit d29f7b1

Please sign in to comment.