SDKs

Each SDK is a single source file you add to your project. It opens the wall for the signed-in user, keeps the wall inside your app, hands surveys to the browser and refreshes the list when the user comes back.

Rewards do not pass through the SDK: your server receives a postback for every completed survey and credits the user. That keeps your secret key out of the app.

Android (Kotlin) · iOS (Swift) · Unity (C#) · Flutter (Dart) · React Native · React (web)

Android (Kotlin)

Add the file to your app and register YetiPollActivity in your manifest, as shown at the top of the file. Download YetiPoll.kt

YetiPoll.open(context, appKey = "yp_test_pk_your_key", userId = currentUser.id)
Show the source
// YetiPoll for Android. Drop this file into your app.
//
//   YetiPoll.open(context, appKey = "yp_live_pk_...", userId = currentUser.id)
//
// Pass `signature` when your app requires signed wall links: compute it on
// your server (HMAC-SHA256 of the user id with your secret key).
package com.yetipoll.sdk

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.webkit.WebResourceRequest
import android.webkit.WebView
import android.webkit.WebViewClient

object YetiPoll {
    private const val HOST = "yetipoll.com"

    fun wallUrl(appKey: String, userId: String, signature: String? = null): String {
        val builder = Uri.Builder().scheme("https").authority(HOST).path("wall")
            .appendQueryParameter("app", appKey)
            .appendQueryParameter("user", userId)
        if (!signature.isNullOrEmpty()) builder.appendQueryParameter("sig", signature)
        return builder.build().toString()
    }

    fun open(context: Context, appKey: String, userId: String, signature: String? = null) {
        val intent = Intent(context, YetiPollActivity::class.java)
            .putExtra("url", wallUrl(appKey, userId, signature))
        if (context !is Activity) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        context.startActivity(intent)
    }
}

// Register in AndroidManifest.xml:
//   <activity android:name="com.yetipoll.sdk.YetiPollActivity" android:exported="false" />
class YetiPollActivity : Activity() {
    private lateinit var web: WebView

    @SuppressLint("SetJavaScriptEnabled")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        web = WebView(this)
        web.settings.javaScriptEnabled = true
        web.settings.domStorageEnabled = true
        web.settings.setSupportMultipleWindows(false)
        web.webViewClient = object : WebViewClient() {
            // The wall stays in the app; surveys open in the user's browser.
            override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
                val url = request.url
                val onWall = url.host == "yetipoll.com" && !(url.path ?: "").startsWith("/wall/go/")
                if (onWall) return false
                startActivity(Intent(Intent.ACTION_VIEW, url))
                return true
            }
        }
        setContentView(web)
        web.loadUrl(intent.getStringExtra("url") ?: return finish())
    }

    override fun onResume() {
        super.onResume()
        web.reload() // fresh surveys when the user comes back from one
    }

    @Deprecated("Deprecated in Java")
    override fun onBackPressed() {
        if (web.canGoBack()) web.goBack() else super.onBackPressed()
    }
}

iOS (Swift)

Add the file to your target. It uses WebKit, which ships with iOS. Download YetiPoll.swift

YetiPoll.present(from: self, appKey: "yp_test_pk_your_key", userId: currentUser.id)
Show the source
// YetiPoll for iOS. Drop this file into your app.
//
//   YetiPoll.present(from: self, appKey: "yp_live_pk_...", userId: currentUser.id)
//
// Pass `signature` when your app requires signed wall links: compute it on
// your server (HMAC-SHA256 of the user id with your secret key).
import UIKit
import WebKit

public enum YetiPoll {
    public static func wallURL(appKey: String, userId: String, signature: String? = nil) -> URL {
        var components = URLComponents(string: "https://yetipoll.com/wall")!
        var items = [URLQueryItem(name: "app", value: appKey), URLQueryItem(name: "user", value: userId)]
        if let signature = signature, !signature.isEmpty {
            items.append(URLQueryItem(name: "sig", value: signature))
        }
        components.queryItems = items
        return components.url!
    }

    public static func present(from presenter: UIViewController, appKey: String, userId: String, signature: String? = nil) {
        let wall = YetiPollViewController(url: wallURL(appKey: appKey, userId: userId, signature: signature))
        presenter.present(UINavigationController(rootViewController: wall), animated: true)
    }
}

public final class YetiPollViewController: UIViewController, WKNavigationDelegate, WKUIDelegate {
    private let url: URL
    private let webView = WKWebView(frame: .zero)

    public init(url: URL) {
        self.url = url
        super.init(nibName: nil, bundle: nil)
    }

    required init?(coder: NSCoder) { fatalError("init(coder:) is not supported") }

    public override func viewDidLoad() {
        super.viewDidLoad()
        title = "Surveys"
        navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(close))
        webView.navigationDelegate = self
        webView.uiDelegate = self
        webView.frame = view.bounds
        webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        view.addSubview(webView)
        webView.load(URLRequest(url: url))
        NotificationCenter.default.addObserver(self, selector: #selector(refresh), name: UIApplication.willEnterForegroundNotification, object: nil)
    }

    @objc private func close() { dismiss(animated: true) }

    // Fresh surveys when the user comes back from one.
    @objc private func refresh() { webView.reload() }

    // Surveys open in a new window: hand them to Safari, keep the wall here.
    public func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
        if let target = navigationAction.request.url {
            UIApplication.shared.open(target)
        }
        return nil
    }
}

Unity (C#)

Add the file to your Assets folder. It opens the wall in the device browser, which works on every platform Unity builds for; to keep it inside your game, load YetiPoll.WallUrl(…) in the web view plugin you already use. Download YetiPoll.cs

YetiPoll.Open("yp_test_pk_your_key", playerId);
Show the source
// YetiPoll for Unity. Add this file to your Assets folder.
//
//   YetiPoll.Open("yp_live_pk_...", playerId);
//
// Opens the wall in the device browser, which works on every platform Unity
// builds for. To keep it inside your game, load YetiPoll.WallUrl(...) in the
// web view plugin you already use.
//
// Pass `signature` when your app requires signed wall links: compute it on
// your server (HMAC-SHA256 of the user id with your secret key).
using System;
using UnityEngine;

public static class YetiPoll
{
    private const string Host = "https://yetipoll.com";

    public static string WallUrl(string appKey, string userId, string signature = null)
    {
        var url = Host + "/wall?app=" + Uri.EscapeDataString(appKey) + "&user=" + Uri.EscapeDataString(userId);
        if (!string.IsNullOrEmpty(signature))
        {
            url += "&sig=" + Uri.EscapeDataString(signature);
        }
        return url;
    }

    public static void Open(string appKey, string userId, string signature = null)
    {
        Application.OpenURL(WallUrl(appKey, userId, signature));
    }
}

Flutter (Dart)

Add the file to your project together with the webview_flutter and url_launcher packages. Download yetipoll.dart

Navigator.push(context, MaterialPageRoute(
  builder: (_) => YetiPollWall(appKey: 'yp_test_pk_your_key', userId: user.id),
));
Show the source
// YetiPoll for Flutter. Add this file to your project.
//
// pubspec.yaml:  webview_flutter and url_launcher
//
//   Navigator.push(context, MaterialPageRoute(
//     builder: (_) => YetiPollWall(appKey: 'yp_live_pk_...', userId: user.id)));
//
// Pass `signature` when your app requires signed wall links: compute it on
// your server (HMAC-SHA256 of the user id with your secret key).
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:webview_flutter/webview_flutter.dart';

Uri yetiPollWallUrl({required String appKey, required String userId, String? signature}) {
  return Uri.https('yetipoll.com', '/wall', {
    'app': appKey,
    'user': userId,
    if (signature != null && signature.isNotEmpty) 'sig': signature,
  });
}

class YetiPollWall extends StatefulWidget {
  const YetiPollWall({super.key, required this.appKey, required this.userId, this.signature});

  final String appKey;
  final String userId;
  final String? signature;

  @override
  State<YetiPollWall> createState() => _YetiPollWallState();
}

class _YetiPollWallState extends State<YetiPollWall> with WidgetsBindingObserver {
  late final WebViewController _controller;

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
    _controller = WebViewController()
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..setNavigationDelegate(NavigationDelegate(
        // The wall stays in the app; surveys open in the user's browser.
        onNavigationRequest: (request) {
          final uri = Uri.parse(request.url);
          final onWall = uri.host == 'yetipoll.com' && !uri.path.startsWith('/wall/go/');
          if (onWall) return NavigationDecision.navigate;
          launchUrl(uri, mode: LaunchMode.externalApplication);
          return NavigationDecision.prevent;
        },
      ))
      ..loadRequest(yetiPollWallUrl(appKey: widget.appKey, userId: widget.userId, signature: widget.signature));
  }

  // Fresh surveys when the user comes back from one.
  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    if (state == AppLifecycleState.resumed) _controller.reload();
  }

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Surveys')),
      body: WebViewWidget(controller: _controller),
    );
  }
}

React Native

Add the file to your project together with react-native-webview. Download YetiPoll.tsx

<YetiPollWall appKey="yp_test_pk_your_key" userId={user.id} style={{ flex: 1 }} />
Show the source
// YetiPoll for React Native. Add this file to your project.
//
// Needs: react-native-webview
//
//   <YetiPollWall appKey="yp_live_pk_..." userId={user.id} />
//
// Pass `signature` when your app requires signed wall links: compute it on
// your server (HMAC-SHA256 of the user id with your secret key).
import React, { useEffect, useRef } from 'react';
import { AppState, Linking, StyleProp, ViewStyle } from 'react-native';
import { WebView } from 'react-native-webview';

export function yetiPollWallUrl(appKey: string, userId: string, signature?: string): string {
  let url = `https://yetipoll.com/wall?app=${encodeURIComponent(appKey)}&user=${encodeURIComponent(userId)}`;
  if (signature) {
    url += `&sig=${encodeURIComponent(signature)}`;
  }
  return url;
}

type Props = { appKey: string; userId: string; signature?: string; style?: StyleProp<ViewStyle> };

export function YetiPollWall({ appKey, userId, signature, style }: Props) {
  const web = useRef<WebView>(null);

  // Fresh surveys when the user comes back from one.
  useEffect(() => {
    const subscription = AppState.addEventListener('change', (state) => {
      if (state === 'active') {
        web.current?.reload();
      }
    });
    return () => subscription.remove();
  }, []);

  return (
    <WebView
      ref={web}
      style={style}
      source={{ uri: yetiPollWallUrl(appKey, userId, signature) }}
      setSupportMultipleWindows={false}
      // The wall stays in the app; surveys open in the user's browser.
      onShouldStartLoadWithRequest={(request) => {
        const onWall = request.url.startsWith('https://yetipoll.com/') && !request.url.includes('/wall/go/');
        if (!onWall) {
          Linking.openURL(request.url);
        }
        return onWall;
      }}
    />
  );
}

React (web)

A component that renders the wall and fits its height. No dependencies beyond React. Download YetiPoll.jsx

<YetiPollWall appKey="yp_test_pk_your_key" userId={user.id} />
Show the source
// YetiPoll for React (web). Add this file to your project.
//
//   <YetiPollWall appKey="yp_live_pk_..." userId={user.id} />
//
// Pass `signature` when your app requires signed wall links: compute it on
// your server (HMAC-SHA256 of the user id with your secret key).
import React, { useEffect, useRef, useState } from 'react';

const ORIGIN = 'https://yetipoll.com';

export function yetiPollWallUrl(appKey, userId, signature) {
  const query = new URLSearchParams({ app: appKey, user: userId, embed: '1' });
  if (signature) {
    query.set('sig', signature);
  }
  return `${ORIGIN}/wall?${query}`;
}

export function YetiPollWall({ appKey, userId, signature, minHeight = 420, onSurveyOpened }) {
  const frame = useRef(null);
  const [height, setHeight] = useState(minHeight);

  useEffect(() => {
    function onMessage(event) {
      if (event.origin !== ORIGIN || !event.data || event.data.source !== 'yetipoll') {
        return;
      }
      if (frame.current && event.source !== frame.current.contentWindow) {
        return;
      }
      if (event.data.type === 'height') {
        setHeight(Math.max(minHeight, Number(event.data.height) || 0));
      }
      if (event.data.type === 'survey_opened' && onSurveyOpened) {
        onSurveyOpened();
      }
    }
    window.addEventListener('message', onMessage);
    return () => window.removeEventListener('message', onMessage);
  }, [minHeight, onSurveyOpened]);

  return (
    <iframe
      ref={frame}
      title="Surveys"
      src={yetiPollWallUrl(appKey, userId, signature)}
      style={{ width: '100%', height, border: 0, display: 'block' }}
    />
  );
}

Signed links

Every SDK takes an optional signature. When your app has "Require signed wall links" on, have your server compute it (how) or fetch a signed address from GET /api/v1/wall-url and hand it to the app.

Another platform

Anything that can show a web page can show the wall. Load this address in a web view:

https://yetipoll.com/wall?app=yp_test_pk_your_key&user=USER_ID