Taplytics Nuxt.js Module
This module integrates Taplytics with your Nuxt.js server rendered application. It injects its API into your app, and applies changes universally (ie, when server rendered and when client rendered).
Installation
yarn add @taplytics/nuxtjs
This module also depends on cookie-universal-nuxt
yarn add cookie-universal-nuxt
Setup
In your nuxt.config.js
, add the following to your modules block:
export default {
...,
modules: [
...,
"@taplytics/nuxtjs",
{
token: "YOUR TOKEN",
ssr: true | false (default to true)
}
],
["cookie-universal-nuxt"]
]
}
Options
Name | Description | Type | Default |
---|
ssr | Enables/disables ssr integration | Boolean | true |
Usage
Web modifications
Web modifications are applied automatically via the server and the client.
SDK
All SDK methods are injected into an app object called $Taplytics
which can be accessed from either the client context or the server context.
All $Taplytics
methods can be accessed via this.$Taplytics
and context.app.$Taplytics
.
featureFlagEnabled
Returns a boolean indicating if the feature flag is enabled for the active user
// from within a template
<p v-if="this.$Taplytics.featureFlagEnabled('someFeatureFlag')">
Feature flag enabled!
</p>
<script>
export default {
mounted() {
if (this.$Taplytics.featureFlagEnabled("someFeatureFlag", false)) {
console.log("Feature flag enabled!");
}
},
};
</script>
if (context.app.$Taplytics.featureFlagEnabled("someFeatureFlag", false)) {
console.log("Feature flag enabled!");
}
variable
Returns a code variable's value
<p v-if="this.$Taplytics.variable('temperature', 50) > 70">
It's nice out!
</p>
runningExperiments
Returns an array of running experiments
if (this.$Taplytics.runningExperiments.length > 0) {
}
codeBlock
Executes a block of code when a user is included in an experiment
this.$Taplytics.codeBlock("runCode", () =>
console.log("this user is included")
);