-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from camunda-community-hub/mixpanel-tracking
feat: Add Mixpanel tracking
- Loading branch information
Showing
11 changed files
with
151 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: feel-scala-playground-secret | ||
type: Opaque | ||
stringData: | ||
mixpanel_project_token: x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/org/camunda/feel/playground/sevice/MixpanelProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.camunda.feel.playground.sevice; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ConditionalOnProperty(prefix = "playground.tracking", name = "enabled", havingValue = "true") | ||
public class MixpanelProperties { | ||
|
||
@Value("${MIXPANEL_PROJECT_TOKEN}") | ||
private String projectToken; | ||
|
||
public String getProjectToken() { | ||
return projectToken; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/org/camunda/feel/playground/sevice/MixpanelTrackingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.camunda.feel.playground.sevice; | ||
|
||
import com.mixpanel.mixpanelapi.MessageBuilder; | ||
import com.mixpanel.mixpanelapi.MixpanelAPI; | ||
import org.json.JSONObject; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
@Component | ||
@ConditionalOnBean(MixpanelProperties.class) | ||
public class MixpanelTrackingService implements TrackingService { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(MixpanelTrackingService.class); | ||
|
||
private final MixpanelAPI mixpanelAPI = new MixpanelAPI(); | ||
|
||
private final MessageBuilder messageBuilder; | ||
|
||
public MixpanelTrackingService(MixpanelProperties mixpanelProperties) { | ||
messageBuilder = new MessageBuilder(mixpanelProperties.getProjectToken()); | ||
} | ||
|
||
private void sendMixpanelEvent(EVENT_TYPE eventType, Map<String, String> metadata) { | ||
|
||
var properties = new JSONObject(); | ||
Optional.ofNullable(metadata).ifPresent(entry -> entry.forEach(properties::put)); | ||
|
||
var message = messageBuilder.event(null, eventType.name(), properties); | ||
|
||
try { | ||
mixpanelAPI.sendMessage(message); | ||
} catch (Exception e) { | ||
LOGGER.warn("Failed to send Mixpanel event.", e); | ||
} | ||
} | ||
|
||
@Override | ||
public void trackExpressionEvaluation(Map<String, String> metadata) { | ||
sendMixpanelEvent(EVENT_TYPE.FEEL_EXPRESSION_EVALUATION, metadata); | ||
} | ||
|
||
@Override | ||
public void trackUnaryTestsExpressionEvaluation(Map<String, String> metadata) { | ||
sendMixpanelEvent(EVENT_TYPE.FEEL_UNARY_TESTS_EXPRESSION_EVALUATION, metadata); | ||
} | ||
|
||
private enum EVENT_TYPE { | ||
FEEL_EXPRESSION_EVALUATION, | ||
FEEL_UNARY_TESTS_EXPRESSION_EVALUATION | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/org/camunda/feel/playground/sevice/NoopTrackingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.camunda.feel.playground.sevice; | ||
|
||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Map; | ||
|
||
@Component | ||
@ConditionalOnMissingBean(MixpanelProperties.class) | ||
public class NoopTrackingService implements TrackingService { | ||
|
||
@Override | ||
public void trackExpressionEvaluation(Map<String, String> metadata) { | ||
// no-op | ||
} | ||
|
||
@Override | ||
public void trackUnaryTestsExpressionEvaluation(Map<String, String> metadata) { | ||
// no-op | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/org/camunda/feel/playground/sevice/TrackingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.camunda.feel.playground.sevice; | ||
|
||
import java.util.Map; | ||
|
||
public interface TrackingService { | ||
|
||
void trackExpressionEvaluation(Map<String, String> metadata); | ||
|
||
void trackUnaryTestsExpressionEvaluation(Map<String, String> metadata); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
server.port=${PORT:8080} | ||
|
||
playground.tracking.enabled=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
server.port=${PORT:8080} | ||
|
||
playground.tracking.enabled=false |