Skip to content

Commit

Permalink
Merge pull request #53 from pluralsh/klink/fix-posthog
Browse files Browse the repository at this point in the history
fix: Incorrect initial capture settings for posthog
  • Loading branch information
dogmar authored Aug 16, 2023
2 parents 437f019 + 3703475 commit cf551b7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/components/hooks/usePosthog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ function setAllowTracking(on?: boolean) {
// opt_in_capturing() or opt_out_capturing() without having run
// posthog.init() first. This generally only occurs when running locally.
if (window && process.env.NEXT_PUBLIC_POSTHOG_API_KEY) {
if (on) {
if (on && !posthog.has_opted_in_capturing()) {
posthog.opt_in_capturing()
} else {
// Make sure to capture initial page view after opting in
posthog.capture('$pageview')
} else if (!on && !posthog.has_opted_out_capturing()) {
posthog.opt_out_capturing()
}
}
Expand All @@ -26,8 +28,7 @@ export function usePosthog() {
api_host:
process.env.NEXT_PUBLIC_POSTHOG_API_HOST ||
'https://posthog.plural.sh',
opt_out_capturing_by_default:
window.Cookiebot?.consent?.statistics ?? false,
opt_out_capturing_by_default: !window.Cookiebot?.consent?.statistics,
loaded: () => {
setAllowTracking(window.Cookiebot?.consent?.statistics)
},
Expand Down
41 changes: 41 additions & 0 deletions src/generated/graphqlPlural.ts
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,10 @@ export type EntityAttributes = {
userId?: InputMaybe<Scalars['ID']['input']>;
};

export enum ExternalOidcProvider {
GithubActions = 'GITHUB_ACTIONS'
}

export type File = {
__typename?: 'File';
blob: Scalars['String']['output'];
Expand Down Expand Up @@ -1772,6 +1776,16 @@ export type OidcStepResponse = {
repository?: Maybe<Repository>;
};

export type OidcTrustRelationship = {
__typename?: 'OidcTrustRelationship';
id: Scalars['ID']['output'];
insertedAt?: Maybe<Scalars['DateTime']['output']>;
issuer: Scalars['String']['output'];
scopes?: Maybe<Array<Scalars['String']['output']>>;
trust: Scalars['String']['output'];
updatedAt?: Maybe<Scalars['DateTime']['output']>;
};

export type OnboardingChecklist = {
__typename?: 'OnboardingChecklist';
dismissed?: Maybe<Scalars['Boolean']['output']>;
Expand Down Expand Up @@ -2680,6 +2694,7 @@ export type RootMutationType = {
createTerraform?: Maybe<Terraform>;
createTest?: Maybe<Test>;
createToken?: Maybe<PersistedToken>;
createTrustRelationship?: Maybe<OidcTrustRelationship>;
createUpgrade?: Maybe<Upgrade>;
createUserEvent?: Maybe<Scalars['Boolean']['output']>;
createWebhook?: Maybe<Webhook>;
Expand Down Expand Up @@ -2714,6 +2729,7 @@ export type RootMutationType = {
deleteStack?: Maybe<Stack>;
deleteTerraform?: Maybe<Terraform>;
deleteToken?: Maybe<PersistedToken>;
deleteTrustRelationship?: Maybe<OidcTrustRelationship>;
deleteUser?: Maybe<User>;
destroyCluster?: Maybe<Scalars['Boolean']['output']>;
deviceLogin?: Maybe<DeviceLogin>;
Expand Down Expand Up @@ -3007,6 +3023,11 @@ export type RootMutationTypeCreateTestArgs = {
};


export type RootMutationTypeCreateTrustRelationshipArgs = {
attributes: TrustRelationshipAttributes;
};


export type RootMutationTypeCreateUpgradeArgs = {
attributes: UpgradeAttributes;
queue: Scalars['String']['input'];
Expand Down Expand Up @@ -3163,6 +3184,11 @@ export type RootMutationTypeDeleteTokenArgs = {
};


export type RootMutationTypeDeleteTrustRelationshipArgs = {
id: Scalars['ID']['input'];
};


export type RootMutationTypeDeleteUserArgs = {
id: Scalars['ID']['input'];
};
Expand Down Expand Up @@ -3594,6 +3620,7 @@ export type RootQueryType = {
oidcConsent?: Maybe<OidcStepResponse>;
oidcLogin?: Maybe<OidcStepResponse>;
oidcLogins?: Maybe<OidcLoginConnection>;
oidcToken?: Maybe<Scalars['String']['output']>;
platformMetrics?: Maybe<PlatformMetrics>;
platformPlans?: Maybe<Array<Maybe<PlatformPlan>>>;
platformSubscription?: Maybe<PlatformSubscription>;
Expand Down Expand Up @@ -3935,6 +3962,13 @@ export type RootQueryTypeOidcLoginsArgs = {
};


export type RootQueryTypeOidcTokenArgs = {
email: Scalars['String']['input'];
idToken: Scalars['String']['input'];
provider: ExternalOidcProvider;
};


export type RootQueryTypePublicKeysArgs = {
after?: InputMaybe<Scalars['String']['input']>;
before?: InputMaybe<Scalars['String']['input']>;
Expand Down Expand Up @@ -4634,6 +4668,12 @@ export enum TestType {
Git = 'GIT'
}

export type TrustRelationshipAttributes = {
issuer: Scalars['String']['input'];
scopes?: InputMaybe<Array<Scalars['String']['input']>>;
trust: Scalars['String']['input'];
};

export type UpdatablePlanAttributes = {
default?: InputMaybe<Scalars['Boolean']['input']>;
serviceLevels?: InputMaybe<Array<InputMaybe<ServiceLevelAttributes>>>;
Expand Down Expand Up @@ -4785,6 +4825,7 @@ export type User = {
publisher?: Maybe<Publisher>;
roles?: Maybe<Roles>;
serviceAccount?: Maybe<Scalars['Boolean']['output']>;
trustRelationships?: Maybe<OidcTrustRelationship>;
updatedAt?: Maybe<Scalars['DateTime']['output']>;
};

Expand Down

0 comments on commit cf551b7

Please sign in to comment.