SDK Client

Our scripts expose SDK Client via `ppg.client` variable

PushPushGo Scripts expose a powerful SDK Client that allows you to customize the behavior and flow of notifications on your website. This guide will walk you through setup, registration, beacon usage, and subscription management using the SDK client.


Overview

The ppg.client object becomes available when the SDK Client is enabled and properly integrated. It provides functionality to:

  • Register and unregister subscriptions

  • Send custom data using beacons

This allows for advanced, programmatic control over how you interact with subscribers and track user behavior or actions.


Setup

  1. Integrate PushPushGo scripts into your website.

  2. Go to your PushPushGo Project Settings.

  3. Toggle "SDK Client" to the enabled state.

  4. Navigate to your website and open the browser console.

  5. You should now see the ppg.client object available globally:

console.log(ppg.client);

Basic Usage

Registering a Subscription

Use the register() method to create or retrieve a current subscription:

const subscriber = await ppg.client.register();

if (!subscriber) {
  console.log('No permission');
  return;
}

console.log('Permission granted');
console.log('Subscriber ID:', subscriber.id);

Working with Beacons

The SDK client allows you to send custom data through beacons—small, structured payloads that track events or attributes.

Using the Beacon Builder

You can send a beacon using a fluent builder interface:

await subscriber.send((beacon) =>
  beacon
    .appendLabel("test")
    .appendLabel("test2", "my_label", "append", 1234)
    .removeLabel("test", "default")
    .setCustomId("123")
    .setField("aaa", "bbb")
);

Using a Beacon Object Directly

Alternatively, you can build a beacon manually and send it:

const beacon = subscriber.beacon();

await beacon
  .appendLabel("test")
  .appendLabel("test2", "my_label", "append", 1234)
  .removeLabel("test", "default")
  .setCustomId("123")
  .setField("aaa", "bbb")
  .send();

Unsubscribing a Subscriber

To remove a subscriber from your notification list:

await subscriber.unsubscribe();

Summary

With PushPushGo's SDK Client, you gain fine-grained control over your web push notification subscriptions and event tracking. Use it to:

  • Seamlessly manage subscription lifecycles

  • Attach meaningful labels and data to subscriber actions

  • Integrate custom tracking and analytics via beacons

For more information, consult your project settings or contact PushPushGo support.

Last updated

Was this helpful?