Skip to content

Commit

Permalink
Merge pull request #582 from pieces-app/query_params_for_download_urls
Browse files Browse the repository at this point in the history
Query params for download urls
  • Loading branch information
judson-at-pieces authored Oct 16, 2024
2 parents 85885f0 + 764e239 commit 91b12bf
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/components/CTAButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {useColorMode} from '@docusaurus/theme-common';
import Image from "../Image";
import React, { useState, useEffect } from 'react';
import Image from '@site/src/components/Image';

type CTAButtonProps = {
label?: string
Expand All @@ -12,15 +13,37 @@ type CTAButtonProps = {
fullWidth?: boolean
}

// Define the type for gaGlobal
interface GaGlobal {
vid: string;
from_cookie: boolean;
}

// Check if gaGlobal exists in the global scope
declare const gaGlobal: GaGlobal | undefined;

const CTAButton = ({ ...props }: CTAButtonProps) => {
const {colorMode} = useColorMode();
const { colorMode } = useColorMode();
const [href, setHref] = useState(props.href);

useEffect(() => {
if (typeof window !== 'undefined' && typeof gaGlobal !== 'undefined') {
const vid = gaGlobal.vid;

if (props.href?.startsWith('https://builds.pieces.app/stages/production')) {
// Need to ensure that vid is defined before appending it to the query string
const updatedHref = `${props.href}?download=true&product=DOCUMENTATION_WEBSITE${vid && `&visitor=${vid}`}`;
setHref(updatedHref);
}
}
}, []);

// If the href starts with http, open in a new tab
const newTab = props.href?.startsWith('http');
const newTab = href?.startsWith('http');

return (
<a
href={props.href}
href={href} // Use the state variable here instead of props.href
className={'cta-button'}
style={{
fontSize: props.type === 'secondary' ? '1rem' : '1.25rem',
Expand All @@ -47,7 +70,6 @@ const CTAButton = ({ ...props }: CTAButtonProps) => {
)
) : null
}

{props.label}
</a>
)
Expand Down

1 comment on commit 91b12bf

@vercel
Copy link

@vercel vercel bot commented on 91b12bf Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.