Skip to content
Snippets Groups Projects
Commit 86862acc authored by Joshua Sedler's avatar Joshua Sedler :cartwheel_tone2:
Browse files

Issue #3502594: Fix failing tests / CI pipeline and clean-up code

parent 4c8eba90
No related branches found
Tags 1.0.0-alpha6
1 merge request!15Issue #3502594: Fix failing tests / CI pipeline and clean-up code
Pipeline #409331 passed with warnings
Showing
with 70 additions and 46 deletions
......@@ -24,8 +24,9 @@ information, see
### Posthog JS SDK & Tracking
For a full list of Initialization-configuration options for the
"Initialization configuration (JSON)" form field (at `/admin/config/services/posthog/js`),
see [here](https://posthog.com/docs/configure/initialization-configuration).
"Initialization configuration (JSON)" form field
(at `/admin/config/services/posthog/js`), see
[here](https://posthog.com/docs/configure/initialization-configuration).
If you would like to do cookie-less tracking, do the following:
- Go to `/admin/config/services/posthog/js` and pass `persistence: "memory"` in
......
......@@ -15,7 +15,10 @@
"posthog/posthog-php": "^3"
},
"require-dev": {
"drupal/cookies": "^2"
"drupal/cookies": "^2",
"drupal/webform": "^6",
"drupal/eca": "^2",
"drupal/commerce": "^3"
},
"suggest": {
"npm-asset/posthog-js": "The posthog-js library, if you'd like to load it locally instead of from Posthog (CDN)",
......
......@@ -8,7 +8,6 @@ use Drupal\posthog_php\SdkInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\commerce_cart\Event\CartEntityAddEvent;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Logger\LoggerChannelFactory;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
/**
......
......@@ -59,6 +59,15 @@ class PosthogCookiesFunctionalJavascriptTest extends WebDriverTestBase {
$this->clearBackendCaches();
}
/**
* Test dummy for now.
*
* @todo Delete this dummy test.
*/
public function testDummy() {
$this->assertTrue(TRUE);
}
// @codingStandardsIgnoreStart
// /**
// * Tests if the cookies ga javascript file is correctly knocked in / out.
......
......@@ -140,7 +140,7 @@ class PosthogEvent extends ConfigurableActionBase {
$properties = [];
if (!empty($this->configuration['custom'])) {
$customPropertiesString = $this->configuration['custom'];
$parsedCustomPropertiesString = \Drupal::service('token')->replace($customPropertiesString);
$parsedCustomPropertiesString = $this->token->replace($customPropertiesString);
$yaml = Yaml::decode($parsedCustomPropertiesString);
$properties = array_merge($properties, $yaml);
}
......
......@@ -4,5 +4,5 @@ description: 'Adds support for Posthog feature flags, for example by providing a
package: "Analytics"
core_version_requirement: ^10.3 || ^11
dependencies:
posthog:posthog_php
- posthog:posthog_php
experimental: true
......@@ -26,6 +26,7 @@ interface SdkInterface {
* E.g. 3.0.3
*
* @return string
* The version.
*/
public static function getVersion(): string;
......@@ -46,6 +47,9 @@ interface SdkInterface {
* ]
*
* @param array $message
* The message to capture.
* @param array $context
* Optional additional context array.
*
* @return bool
* Whether the capture call succeeded
......@@ -73,6 +77,8 @@ interface SdkInterface {
* [
* '$current_url' => 'https://example.com'
* ].
* @param array $context
* Optional additional context array.
*
* @return bool
* Whether the capture call succeeded
......@@ -88,6 +94,8 @@ interface SdkInterface {
* The distinct user id.
* @param string $currentUrl
* The current URL.
* @param array $context
* Optional additional context array.
*
* @return bool
* Whether the capture call succeeded
......@@ -130,14 +138,25 @@ interface SdkInterface {
* Tells if the feature flag is enabled for this distinct id.
*
* @param string $key
* The feature flag key.
* @param string $distinctId
* The distinct user id.
* @param array $groups
* Optional additional groups array.
* @param array $personProperties
* Optional additional person properties array.
* @param array $groupProperties
* Optional additional group properties array.
* @param bool $onlyEvaluateLocally
* Whether to only evaluate locally.
* @param bool $sendFeatureFlagEvents
* Whether to send feature flag events.
*
* @return bool
* @return bool|null
* Whether the feature flag is enabled or null if not evaluated.
*
* @throws Exception.
* @throws \Exception
* If an error occurs.
*/
public function isFeatureEnabled(
string $key,
......@@ -150,17 +169,28 @@ interface SdkInterface {
): NULL | bool;
/**
* Get the feature flag value for this distinct id.
* Retrieves the feature flag value for a given distinct ID.
*
* @param string $key
* The key of the feature flag.
* @param string $distinctId
* The distinct ID to check the feature flag for.
* @param array $groups
* (optional) An array of groups to consider.
* @param array $personProperties
* (optional) An array of person properties to consider.
* @param array $groupProperties
* (optional) An array of group properties to consider.
* @param bool $onlyEvaluateLocally
* (optional) Whether to only evaluate the feature flag locally.
* @param bool $sendFeatureFlagEvents
* (optional) Whether to send feature flag events.
*
* @return boolean | string
* @return bool|string
* The value of the feature flag, which can be a boolean or a string.
*
* @throws Exception.
* @throws \Exception
* Thrown when there is an error retrieving the feature flag value.
*/
public function getFeatureFlag(
string $key,
......@@ -173,33 +203,18 @@ interface SdkInterface {
): null | bool | string;
/**
* Get all enabled flags for distinct_id.
* Fetches the feature variants for a given distinct ID.
*
* @param string $distinctId
* The distinct user ID.
* @param array $groups
* @param array $personProperties
* @param array $groupProperties
*
* @return array
*
* @throws Exception
*/
public function getAllFlags(
string $distinctId,
array $groups = [],
array $personProperties = [],
array $groupProperties = [],
bool $onlyEvaluateLocally = FALSE,
): array;
/**
* Fetch the feature variants.
*
* @param string $distinctId
* (optional) An array of groups to consider.
*
* @return array
* An array of feature variants.
*
* @throws Exception
* @throws \Exception
* Thrown when there is an error fetching the feature variants.
*/
public function fetchFeatureVariants(string $distinctId, array $groups = []): array;
......@@ -213,7 +228,8 @@ interface SdkInterface {
* @param mixed $alias
* The alias.
*
* @return boolean whether the alias call succeeded
* @return bool
* Whether the alias call succeeded.
*
* @throws Exception.
*/
......@@ -234,9 +250,12 @@ interface SdkInterface {
* Validate common properties.
*
* @param array $msg
* The message to validate.
* @param string $type
* The type of validation.
*
* @throws Exception
* @throws \Exception
* If validation fails.
*/
public function validate($msg, $type): void;
......
<?php
/**
* @file
* Install, update and uninstall functions for the Posthog JS Error Tracking module.
*/
......@@ -42,9 +42,8 @@ final class PosthogPhpEventsSubscriber implements EventSubscriberInterface {
if (!$event->isMainRequest()) {
return;
}
$response = $event->getResponse();
$isAjaxResponse = $response instanceof AjaxResponse;
// $response = $event->getResponse();
// $isAjaxResponse = $response instanceof AjaxResponse;
// @todo Track event
}
......
......@@ -80,13 +80,14 @@ final class SettingsForm extends ConfigFormBase {
'#description' => $this->t('Event name is "User deleted".'),
'#default_value' => $config->get('track_drupal_user_delete'),
];
// @codingStandardsIgnoreStart
// @todo Implement subscriber events:
// $form['subscriber_events'] = [
// '#type' => 'details',
// '#title' => $this->t('Subscriber events'),
// '#open' => TRUE,
// ];
// @codingStandardsIgnoreEnd
return parent::buildForm($form, $form_state);
}
......
......@@ -56,7 +56,6 @@ class PosthogWebformHandler extends WebformHandlerBase {
$instance->userAttributesProvider = $container->get('posthog.user_attributes_provider');
$instance->posthogSdk = $container->get('posthog_php.sdk');
$instance->token = $container->get('token');
return $instance;
}
......@@ -117,7 +116,7 @@ class PosthogWebformHandler extends WebformHandlerBase {
'#token_types' => [],
];
try {
$rendered_token_tree = \Drupal::service('renderer')->render($token_tree);
$rendered_token_tree = $this->renderer->render($token_tree);
}
catch (\Exception $e) {
$rendered_token_tree = '';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment