> ## Documentation Index
> Fetch the complete documentation index at: https://usegately.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Installation

> Install the Gately SDK in your project

## Package Installation

<Tabs>
  <Tab title="NPM">
    ```bash theme={null}
    npm install @gately/sdk
    ```
  </Tab>

  <Tab title="Yarn">
    ```bash theme={null}
    yarn add @gately/sdk
    ```
  </Tab>

  <Tab title="pnpm">
    ```bash theme={null}
    pnpm add @gately/sdk
    ```
  </Tab>
</Tabs>

## CDN Installation

For quick prototyping or non-bundled projects, use the CDN:

```html theme={null}
<script 
  src="https://cdn.usegately.com/gately.min.js" 
  data-api-key="YOUR_API_KEY"
  defer
></script>
```

The SDK will be available globally as `window.Gately`.

### CDN Options

```html theme={null}
<script 
  src="https://cdn.usegately.com/gately.min.js" 
  data-api-key="YOUR_API_KEY"
  data-auto-init="true"
  data-auto-protect="true"
  defer
></script>
```

| Attribute           | Description                 | Default  |
| ------------------- | --------------------------- | -------- |
| `data-api-key`      | Your Gately API key         | Required |
| `data-auto-init`    | Auto-initialize the SDK     | `true`   |
| `data-auto-protect` | Auto-enable page protection | `true`   |

<Info>
  Get your API key from **Settings → API Keys** in your [Gately dashboard](https://app.usegately.com).
</Info>

## Framework-Specific Setup

### React

```jsx theme={null}
import { GatelyProvider } from '@gately/sdk'

function App() {
  return (
    <GatelyProvider apiKey="gately_pk_live_xxxxxxxx">
      <YourApp />
    </GatelyProvider>
  )
}
```

### Next.js

```jsx theme={null}
// app/providers.tsx
'use client'

import { GatelyProvider } from '@gately/sdk'

export function Providers({ children }) {
  return (
    <GatelyProvider apiKey={process.env.NEXT_PUBLIC_GATELY_API_KEY}>
      {children}
    </GatelyProvider>
  )
}

// app/layout.tsx
import { Providers } from './providers'

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        <Providers>{children}</Providers>
      </body>
    </html>
  )
}
```

### Vue.js

```javascript theme={null}
// main.js
import { createApp } from 'vue'
import { GatelyClient } from '@gately/sdk'

const app = createApp(App)

// Create and provide the client
const gately = new GatelyClient({
  apiKey: 'gately_pk_live_xxxxxxxx'
})
app.provide('gately', gately)

app.mount('#app')
```

```vue theme={null}
<!-- Component.vue -->
<script setup>
import { inject } from 'vue'
const gately = inject('gately')
</script>
```

### Vanilla JavaScript

```javascript theme={null}
import { GatelyClient } from '@gately/sdk'

const gately = new GatelyClient({
  apiKey: 'gately_pk_live_xxxxxxxx'
})

// Use the client
document.getElementById('login-btn').addEventListener('click', async () => {
  const email = document.getElementById('email').value
  const password = document.getElementById('password').value
  
  try {
    await gately.login(email, password)
    window.location.href = '/dashboard'
  } catch (error) {
    alert(error.message)
  }
})
```

## Framer Integration

For Framer sites, add the SDK via custom code:

1. Open your Framer project
2. Go to **Site Settings > General > Custom Code**
3. Add to the `<head>` section:

```html theme={null}
<script 
  src="https://cdn.usegately.com/gately.min.js" 
  data-api-key="YOUR_API_KEY"
  defer
></script>
```

4. Use in code overrides:

```javascript theme={null}
export function withAuth(Component) {
  return (props) => {
    const [user, setUser] = React.useState(null)
    
    React.useEffect(() => {
      if (window.Gately) {
        setUser(window.Gately.getUser())
        window.Gately.onAuthStateChange((user) => setUser(user))
      }
    }, [])
    
    return <Component {...props} user={user} />
  }
}
```

## Webflow Integration

1. Go to **Project Settings > Custom Code**
2. Add to the **Head Code** section:

```html theme={null}
<script 
  src="https://cdn.usegately.com/gately.min.js" 
  data-api-key="YOUR_API_KEY"
  defer
></script>
```

3. Add to the **Footer Code** section:

```html theme={null}
<script>
  document.addEventListener('DOMContentLoaded', function() {
    // SDK is ready
    if (window.Gately.isAuthenticated()) {
      // Show logged-in content
      document.querySelectorAll('.logged-in-only').forEach(el => {
        el.style.display = 'block'
      })
    }
  })
</script>
```

## Verifying Installation

After installation, verify the SDK is working:

```javascript theme={null}
import { GatelyClient } from '@gately/sdk'

const gately = new GatelyClient({
  apiKey: 'gately_pk_live_xxxxxxxx'
})

// Check authentication status
console.log('Authenticated:', gately.isAuthenticated())

// Get current user (if logged in)
const user = gately.getUser()
console.log('User:', user)
```

## Troubleshooting

<AccordionGroup>
  <Accordion title="Module not found">
    Ensure you've installed the package:

    ```bash theme={null}
    npm install @gately/sdk
    ```
  </Accordion>

  <Accordion title="Invalid API key">
    * Check that your API key starts with `gately_pk_` (public) or `gately_sk_` (secret)
    * Verify it matches your project in the dashboard
    * Ensure you're using the correct key type for your environment
  </Accordion>

  <Accordion title="CORS errors">
    * Ensure your domain is added to the allowed origins in project settings
    * Check that you're using HTTPS in production
  </Accordion>

  <Accordion title="SDK not loading (CDN)">
    * Check browser console for errors
    * Verify the script URL is correct
    * Ensure `defer` attribute is present
  </Accordion>
</AccordionGroup>
