Skip to content

Commit

Permalink
add wrapper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
arcdigital committed Feb 18, 2023
1 parent c619119 commit 2cfebbf
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/PostHog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Arcdigital\PostHog;

use PostHog\PostHog as PostHogClient;

class PostHog
{
private static ?string $distinctId = null;

public static function setDistinctId(string $id): void
{
self::$distinctId = $id;
}

/**
* @param array<string, mixed> $properties
*
* @throws \Exception
*/
public static function capture(string $event, array $properties = null, string $id = null): bool
{
return PostHogClient::capture([
'distinctId' => self::$distinctId ?? $id,
'event' => $event,
'properties' => $properties,
]);
}

/**
* @param array<string, mixed> $properties
*
* @throws \Exception
*/
public static function identify(string $id, array $properties): bool
{
return PostHogClient::identify([
'distinctId' => $id,
'properties' => $properties,
]);
}

/**
* @throws \Exception
*/
public static function alias(string $id, string $alias): bool
{
return PostHogClient::alias([
'distinctId' => $id,
'alias' => $alias,
]);
}
}

0 comments on commit 2cfebbf

Please sign in to comment.