This is a library to help with authenticating requests to and from PeekPro when writing apps.
config :peek_app_sdk,
peek_app_secret: "APP_SECRET",
peek_app_id: "APP_ID",
peek_api_url: "https://apps.peekapis.com/backoffice-gql",
peek_app_key: "APP_KEY"
PeekAppSDK supports multiple configurations, allowing different applications to use their own credentials through a centralized configuration structure:
# Default configuration
config :peek_app_sdk,
peek_app_secret: "DEFAULT_SECRET",
peek_app_id: "DEFAULT_APP_ID",
peek_api_url: "https://apps.peekapis.com/backoffice-gql",
peek_app_key: "DEFAULT_APP_KEY",
# Centralized app configurations
apps: [
project_name: [peek_app_id: "project_name_APP_ID", peek_app_secret: "project_name_APP_SECRET"],
another_app: [peek_app_id: "ANOTHER_APP_ID", peek_app_secret: "ANOTHER_APP_SECRET"]
]
Then use the application identifier when calling PeekAppSDK functions:
# Using default configuration
PeekAppSDK.query_peek_pro("install_id", "query { test }")
# Using application-specific configuration
PeekAppSDK.query_peek_pro("install_id", "query { test }", %{}, :project_name)
Note that peek_api_url
and peek_app_key
are always taken from the default configuration.
import PeekAppSDK.Plugs.PeekAuth
in routerplug :set_peek_install_id
can be used for routes that need to verify a peek request. This will set apeek_install_id
prop in theassigns
of theconn
live_session :some_live_view_session_scope, on_mount: {PeekAppSDK.Plugs.PeekAuth, :set_install_id_for_live_view}
will set thepeek_install_id
on the Socket for live view usage.
To use PeekAppSDK's Tailwind styles in your application:
- make sure hero-icons is in your deps:
{:heroicons, github: "tailwindlabs/heroicons", tag: "v2.1.1", sparse: "optimized", app: false, compile: false, depth: 1}
- In your application's
assets/tailwind.config.js
, extend the configuration:
// Import PeekAppSDK's Tailwind config
const path = require('path')
const peekSDKConfig = require('../../../deps/peek_app_sdk/assets/tailwind.config.js')
const sdkConfig = peekSDKConfig({
heroiconsPath: path.join(__dirname, '../deps/heroicons/optimized')
})
module.exports = {
content: [
'./js/**/*.js',
'../lib/project_name_web.ex',
'../lib/project_name_web/**/*.*ex',
'../lib/project_name_web/controllers/**/*.html.heex',
// add one of the following line, adjust to your needs
'../deps/peek_app_sdk/lib/peek_app_sdk/**/*.*ex', // this is if you are in a single elixir app
'../../../deps/peek_app_sdk/lib/peek_app_sdk/**/*.*ex' // this is if you are in an umbrella app
],
theme: {
extend: {
...sdkConfig.theme.extend
}
},
plugins: [...sdkConfig.plugins]
}
This will ensure your application includes all the necessary styles for PeekAppSDK components.
This document describes how to use the metrics functionality in the PeekAppSDK.
The PeekAppSDK provides a simple function for tracking metrics:
track/2
- Track any event with flexible payload
The track/2
function provides a simple and flexible way to track events with any fields you need. It takes an event ID and a map of fields, and sends them directly to the metrics service without any validation or transformation.
event_id
- The ID of the event to track (e.g., "app.install", "user.login")payload
- A map containing any fields you want to include in the event
PeekAppSDK.Metrics.track("app.install", %{
anonymousId: "partner-123",
level: "info"
})
PeekAppSDK.Metrics.track("app.install", %{
# Required
anonymousId: "partner-123",
level: "info",
# Optional, useful for additional metrics features
usageDisplay: "New App Installs",
usageDetails: "Bob's Surf",
postMessage: "Bob's Surf installed",
# Optional, useful for data analysis
userId: "user-456",
idempotencyKey: "unique-key-789",
context: %{
channel: "web",
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)",
sessionId: "session-123",
timezone: "America/Los_Angeles",
ip: "192.168.1.1",
page: "/install",
screen: %{
height: 1080,
width: 1920
}
},
customFields: %{
"partnerId" => "partner-123",
"partnerName" => "Bob's Surf",
"partnerIsTest" => false
}
})
The track/2
function is designed to be as flexible as possible. You can include any fields you need in the payload, and they will be sent directly to the metrics service. This allows you to track custom events with any data structure you need.
PeekAppSDK.Metrics.track("custom.event", %{
anonymousId: "user-123",
someCustomField: "custom value",
nestedData: %{
key1: "value1",
key2: "value2"
},
arrayData: [1, 2, 3]
})
While the track/2
function doesn't enforce any specific field names, here are some common field names that are used in the metrics service:
Field Name | Description |
---|---|
anonymousId |
Identifier for the event (usually partner ID or user ID) |
level |
Event level (e.g., "info", "error") |
usageDisplay |
Display name for usage metrics |
usageDetails |
Details for usage metrics |
postMessage |
Message to post with the event |
userId |
User ID associated with the event |
idempotencyKey |
Key to prevent duplicate events |
context |
Contextual information about the event |
customFields |
Custom fields to include with the event |
Here are some common event types that are used in the metrics service:
app.install
- App installationapp.uninstall
- App uninstallationuser.login
- User loginuser.logout
- User logoutapp.error
- Application error