Skip to content

Commit

Permalink
feat: adds rudder analytics (matter-labs#662)
Browse files Browse the repository at this point in the history
* feat: adds rudder analytics

* fix: build fix - only run code on client side

---------

Co-authored-by: Antonio <[email protected]>
  • Loading branch information
githubdoramon and uF4No authored Aug 23, 2023
1 parent f868af3 commit 2aedac6
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ jobs:
yarn install
- name: "Deploy production"
run: yarn run docs:build
env:
RUDDERSTACK_WRITE_KEY: "${{ secrets.RUDDERSTACK_WRITE_KEY }}"
RUDDERSTACK_DATA_PLANE_URL: "${{ secrets.RUDDERSTACK_DATA_PLANE_URL }}"


- name: "Copy 404"
run: |
Expand Down
30 changes: 30 additions & 0 deletions docs/.vuepress/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { defineClientConfig } from '@vuepress/client'

export default defineClientConfig({
enhance({ app, router }) {

if (!__VUEPRESS_SSR__) {
router.isReady().then(() => {

const rudderScript = document.createElement('script')
rudderScript.innerHTML = `
rudderanalytics = window.rudderanalytics=[];
for(var methods=["load","page","track","identify","reset"],i=0;i<methods.length;i++){var method=methods[i];rudderanalytics[method]=function(a){return function(){rudderanalytics.push([a].concat(Array.prototype.slice.call(arguments)))}}(method)}
rudderanalytics.load(__RUDDER_WRITE_KEY__, __RUDDERSTACK_DATA_PLANE_URL__);
`;
document.head.appendChild(rudderScript)

const rudderSDK = document.createElement('script')
rudderSDK.src = `https://cdn.rudderlabs.com/rudder-analytics.min.js`
rudderSDK.onload = function() {
rudderanalytics.page();

router.afterEach(function (to) {
rudderanalytics.page();
})
}
document.head.appendChild(rudderSDK)
})
};
}
})
10 changes: 9 additions & 1 deletion docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import vue from "@vitejs/plugin-vue";
import theme from "./theme.js";
import { pwaPlugin } from "vuepress-plugin-pwa2";
import { getDirname, path } from "@vuepress/utils";
import * as dotenv from 'dotenv'
import { seoPlugin } from "vuepress-plugin-seo2";

import { registerComponentsPlugin } from "@vuepress/plugin-register-components";

dotenv.config()


const dirname = getDirname(import.meta.url);

export default defineUserConfig({
Expand Down Expand Up @@ -107,6 +110,11 @@ export default defineUserConfig({

theme,

define: {
__RUDDER_WRITE_KEY__: process.env.RUDDERSTACK_WRITE_KEY,
__RUDDERSTACK_DATA_PLANE_URL__: process.env.RUDDERSTACK_DATA_PLANE_URL,
},

plugins: [
seoPlugin,
pwaPlugin({
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"check-md": "^1.0.2",
"commitlint": "^17.3.0",
"cspell": "^6.18.1",
"dotenv": "^16.3.1",
"husky": "^8.0.3",
"lint-staged": "^13.1.0",
"markdownlint": "^0.27.0",
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6611,6 +6611,13 @@ __metadata:
languageName: node
linkType: hard

"dotenv@npm:^16.3.1":
version: 16.3.1
resolution: "dotenv@npm:16.3.1"
checksum: 15d75e7279018f4bafd0ee9706593dd14455ddb71b3bcba9c52574460b7ccaf67d5cf8b2c08a5af1a9da6db36c956a04a1192b101ee102a3e0cf8817bbcf3dfd
languageName: node
linkType: hard

"duplexer2@npm:~0.1.0":
version: 0.1.4
resolution: "duplexer2@npm:0.1.4"
Expand Down Expand Up @@ -13931,6 +13938,7 @@ __metadata:
check-md: ^1.0.2
commitlint: ^17.3.0
cspell: ^6.18.1
dotenv: ^16.3.1
husky: ^8.0.3
lint-staged: ^13.1.0
markdownlint: ^0.27.0
Expand Down

0 comments on commit 2aedac6

Please sign in to comment.