New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

posthog-js

Package Overview
Dependencies
Maintainers
0
Versions
764
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

posthog-js - npm Package Compare versions

Comparing version

to
1.143.0

8

dist/lib/src/extensions/surveys/surveys-utils.d.ts

@@ -15,2 +15,10 @@ import { PostHog } from '../../posthog-core';

export declare const getDisplayOrderQuestions: (survey: Survey) => SurveyQuestion[];
export declare const hasEvents: (survey: Survey) => boolean;
export declare const canActivateRepeatedly: (survey: Survey) => boolean;
/**
* getSurveySeen checks local storage for the surveySeen Key a
* and overrides this value if the survey can be repeatedly activated by its events.
* @param survey
*/
export declare const getSurveySeen: (survey: Survey) => boolean;
export declare const getSurveySeenKey: (survey: Survey) => string;

@@ -17,0 +25,0 @@ export declare const SurveyContext: import("preact").Context<{

2

dist/lib/src/posthog-core.d.ts

@@ -142,3 +142,3 @@ import { PostHogFeatureFlags } from './posthog-featureflags';

capture(event_name: string, properties?: Properties | null, options?: CaptureOptions): CaptureResult | void;
_addCaptureHook(callback: (eventName: string) => void): void;
_addCaptureHook(callback: (eventName: string, eventPayload?: CaptureResult) => void): void;
_calculate_event_properties(event_name: string, event_properties: Properties, options?: CaptureOptions): Properties;

@@ -145,0 +145,0 @@ _calculate_set_once_properties(dataSetOnce?: Properties): Properties | undefined;

@@ -117,2 +117,3 @@ /**

events: {
repeatedActivation?: boolean;
values: {

@@ -119,0 +120,0 @@ name: string;

import { Survey } from '../posthog-surveys-types';
import { PostHogPersistence } from '../posthog-persistence';
import { CaptureResult } from '../types';
export declare class SurveyEventReceiver {
private readonly eventRegistry;
private readonly persistence?;
private static SURVEY_SHOWN_EVENT_NAME;
constructor(persistence?: PostHogPersistence);
register(surveys: Survey[]): void;
on(event: string): void;
on(event: string, eventPayload?: CaptureResult): void;
getSurveys(): string[];

@@ -10,0 +12,0 @@ getEventRegistry(): Map<string, string[]>;

{
"name": "posthog-js",
"version": "1.142.1",
"version": "1.143.0",
"description": "Posthog-js allows you to automatically capture usage and send events to PostHog.",

@@ -5,0 +5,0 @@ "repository": "https://github.com/PostHog/posthog-js",

@@ -39,3 +39,3 @@ var __assign = (this && this.__assign) || function () {

import { window as _window, document as _document } from '../utils/globals';
import { style, defaultSurveyAppearance, sendSurveyEvent, dismissedSurveyEvent, createShadow, getContrastingTextColor, SurveyContext, getDisplayOrderQuestions, getSurveySeenKey, } from './surveys/surveys-utils';
import { style, defaultSurveyAppearance, sendSurveyEvent, dismissedSurveyEvent, createShadow, getContrastingTextColor, SurveyContext, getDisplayOrderQuestions, getSurveySeen, } from './surveys/surveys-utils';
import * as Preact from 'preact';

@@ -80,3 +80,4 @@ import { createWidgetShadow, createWidgetStyle } from './surveys-widget';

}
if (!localStorage.getItem(getSurveySeenKey(survey))) {
var surveySeen = getSurveySeen(survey);
if (!surveySeen) {
_this.addSurveyToFocus(survey.id);

@@ -83,0 +84,0 @@ var shadow = createShadow(style(survey === null || survey === void 0 ? void 0 : survey.appearance), survey.id);

@@ -15,2 +15,10 @@ import { PostHog } from '../../posthog-core';

export declare const getDisplayOrderQuestions: (survey: Survey) => SurveyQuestion[];
export declare const hasEvents: (survey: Survey) => boolean;
export declare const canActivateRepeatedly: (survey: Survey) => boolean;
/**
* getSurveySeen checks local storage for the surveySeen Key a
* and overrides this value if the survey can be repeatedly activated by its events.
* @param survey
*/
export declare const getSurveySeen: (survey: Survey) => boolean;
export declare const getSurveySeenKey: (survey: Survey) => string;

@@ -17,0 +25,0 @@ export declare const SurveyContext: import("preact").Context<{

@@ -319,2 +319,24 @@ var __assign = (this && this.__assign) || function () {

};
export var hasEvents = function (survey) {
var _a, _b, _c, _d, _e, _f;
return ((_c = (_b = (_a = survey.conditions) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.values) === null || _c === void 0 ? void 0 : _c.length) != undefined && ((_f = (_e = (_d = survey.conditions) === null || _d === void 0 ? void 0 : _d.events) === null || _e === void 0 ? void 0 : _e.values) === null || _f === void 0 ? void 0 : _f.length) > 0;
};
export var canActivateRepeatedly = function (survey) {
var _a, _b;
return !!(((_b = (_a = survey.conditions) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.repeatedActivation) && hasEvents(survey));
};
/**
* getSurveySeen checks local storage for the surveySeen Key a
* and overrides this value if the survey can be repeatedly activated by its events.
* @param survey
*/
export var getSurveySeen = function (survey) {
var surveySeen = localStorage.getItem(getSurveySeenKey(survey));
if (surveySeen) {
// if a survey has already been seen,
// we will override it with the event repeated activation value.
return !canActivateRepeatedly(survey);
}
return false;
};
export var getSurveySeenKey = function (survey) {

@@ -321,0 +343,0 @@ var surveySeenKey = "seenSurvey_".concat(survey.id);

@@ -142,3 +142,3 @@ import { PostHogFeatureFlags } from './posthog-featureflags';

capture(event_name: string, properties?: Properties | null, options?: CaptureOptions): CaptureResult | void;
_addCaptureHook(callback: (eventName: string) => void): void;
_addCaptureHook(callback: (eventName: string, eventPayload?: CaptureResult) => void): void;
_calculate_event_properties(event_name: string, event_properties: Properties, options?: CaptureOptions): Properties;

@@ -145,0 +145,0 @@ _calculate_set_once_properties(dataSetOnce?: Properties): Properties | undefined;

@@ -117,2 +117,3 @@ /**

events: {
repeatedActivation?: boolean;
values: {

@@ -119,0 +120,0 @@ name: string;

@@ -8,2 +8,3 @@ import { SURVEYS } from './constants';

import { isUndefined } from './utils/type-utils';
import { canActivateRepeatedly, hasEvents } from './extensions/surveys/surveys-utils';
export var surveyUrlValidationMap = {

@@ -100,5 +101,5 @@ icontains: function (conditionsUrl) {

(_b = _this._surveyEventReceiver) === null || _b === void 0 ? void 0 : _b.register(eventBasedSurveys);
var onEventName = function (eventName) {
var onEventName = function (eventName, eventPayload) {
var _a;
(_a = _this._surveyEventReceiver) === null || _a === void 0 ? void 0 : _a.on(eventName);
(_a = _this._surveyEventReceiver) === null || _a === void 0 ? void 0 : _a.on(eventName, eventPayload);
};

@@ -141,3 +142,2 @@ _this.instance._addCaptureHook(onEventName);

var targetingMatchedSurveys = conditionMatchedSurveys.filter(function (survey) {
var _a, _b, _c, _d, _e;
if (!survey.linked_flag_key && !survey.targeting_flag_key && !survey.internal_targeting_flag_key) {

@@ -152,9 +152,7 @@ return true;

: true;
var internalTargetingFlagCheck = survey.internal_targeting_flag_key
var eventBasedTargetingFlagCheck = hasEvents(survey) ? activatedSurveys === null || activatedSurveys === void 0 ? void 0 : activatedSurveys.includes(survey.id) : true;
var overrideInternalTargetingFlagCheck = canActivateRepeatedly(survey);
var internalTargetingFlagCheck = survey.internal_targeting_flag_key && !overrideInternalTargetingFlagCheck
? _this.instance.featureFlags.isFeatureEnabled(survey.internal_targeting_flag_key)
: true;
var hasEvents = ((_a = survey.conditions) === null || _a === void 0 ? void 0 : _a.events) &&
((_c = (_b = survey.conditions) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.values) &&
((_e = (_d = survey.conditions) === null || _d === void 0 ? void 0 : _d.events) === null || _e === void 0 ? void 0 : _e.values.length) > 0;
var eventBasedTargetingFlagCheck = hasEvents ? activatedSurveys === null || activatedSurveys === void 0 ? void 0 : activatedSurveys.includes(survey.id) : true;
return (linkedFlagCheck && targetingFlagCheck && internalTargetingFlagCheck && eventBasedTargetingFlagCheck);

@@ -161,0 +159,0 @@ });

import { Survey } from '../posthog-surveys-types';
import { PostHogPersistence } from '../posthog-persistence';
import { CaptureResult } from '../types';
export declare class SurveyEventReceiver {
private readonly eventRegistry;
private readonly persistence?;
private static SURVEY_SHOWN_EVENT_NAME;
constructor(persistence?: PostHogPersistence);
register(surveys: Survey[]): void;
on(event: string): void;
on(event: string, eventPayload?: CaptureResult): void;
getSurveys(): string[];

@@ -10,0 +12,0 @@ getEventRegistry(): Map<string, string[]>;

@@ -43,13 +43,26 @@ var __read = (this && this.__read) || function (o, n) {

};
SurveyEventReceiver.prototype.on = function (event) {
var _a;
SurveyEventReceiver.prototype.on = function (event, eventPayload) {
var _a, _b;
var activatedSurveys = [];
this.eventRegistry.forEach(function (events, surveyID) {
if (events.includes(event)) {
activatedSurveys.push(surveyID);
var existingActivatedSurveys = ((_a = this.persistence) === null || _a === void 0 ? void 0 : _a.props[SURVEYS_ACTIVATED]) || [];
if (SurveyEventReceiver.SURVEY_SHOWN_EVENT_NAME == event &&
eventPayload &&
existingActivatedSurveys.length > 0) {
// remove survey that from activatedSurveys here.
var surveyId = (_b = eventPayload === null || eventPayload === void 0 ? void 0 : eventPayload.properties) === null || _b === void 0 ? void 0 : _b.$survey_id;
if (surveyId) {
var index = existingActivatedSurveys.indexOf(surveyId);
if (index >= 0) {
existingActivatedSurveys.splice(index, 1);
}
}
});
var existingActivatedSurveys = (_a = this.persistence) === null || _a === void 0 ? void 0 : _a.props[SURVEYS_ACTIVATED];
var existingSurveys = existingActivatedSurveys ? existingActivatedSurveys : [];
var updatedSurveys = existingSurveys.concat(activatedSurveys);
}
else {
this.eventRegistry.forEach(function (events, surveyID) {
if (events.includes(event)) {
activatedSurveys.push(surveyID);
}
});
}
var updatedSurveys = existingActivatedSurveys.concat(activatedSurveys);
this._saveSurveysToStorage(updatedSurveys);

@@ -73,2 +86,3 @@ };

};
SurveyEventReceiver.SURVEY_SHOWN_EVENT_NAME = 'survey shown';
return SurveyEventReceiver;

@@ -75,0 +89,0 @@ }());

{
"name": "posthog-js",
"version": "1.142.1",
"version": "1.143.0",
"description": "Posthog-js allows you to automatically capture usage and send events to PostHog.",

@@ -5,0 +5,0 @@ "repository": "https://github.com/PostHog/posthog-js",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet