Skip to content

Commit

Permalink
Merge pull request #1295 from sundowndev/feat/analytics
Browse files Browse the repository at this point in the history
Implement analytics in demo website
  • Loading branch information
sundowndev authored Jun 29, 2023
2 parents 3083517 + 740c23c commit af11276
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 4 deletions.
9 changes: 8 additions & 1 deletion build/build.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package build

import "fmt"
import (
"fmt"
"os"
)

// Version is the corresponding release tag
var Version = "dev"
Expand All @@ -15,3 +18,7 @@ func IsRelease() bool {
func String() string {
return fmt.Sprintf("%s-%s", Version, Commit)
}

func IsDemo() bool {
return os.Getenv("PHONEINFOGA_DEMO") == "true"
}
6 changes: 6 additions & 0 deletions build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package build

import (
"github.com/stretchr/testify/assert"
"os"
"testing"
)

Expand All @@ -11,12 +12,17 @@ func TestBuild(t *testing.T) {
assert.Equal(t, "dev", Commit)
assert.Equal(t, false, IsRelease())
assert.Equal(t, "dev-dev", String())
assert.Equal(t, false, IsDemo())
})

t.Run("version and commit default values", func(t *testing.T) {
Version = "v2.4.4"
Commit = "0ba854f"
_ = os.Setenv("PHONEINFOGA_DEMO", "true")
defer os.Unsetenv("PHONEINFOGA_DEMO")

assert.Equal(t, true, IsRelease())
assert.Equal(t, "v2.4.4-0ba854f", String())
assert.Equal(t, true, IsDemo())
})
}
13 changes: 11 additions & 2 deletions web/client/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<b-container class="my-md-3">
<b-row>
<b-col cols="12">
<b-alert show variant="warning" fade>Welcome to the demo of PhoneInfoga web client.</b-alert>
<b-alert
v-for="(err, i) in errors"
v-bind:key="i"
Expand Down Expand Up @@ -84,6 +85,13 @@
</b-navbar-nav>
</b-container>
</b-navbar>
<script
v-if="isDemo"
type="application/javascript"
defer
data-domain="demo.phoneinfoga.crvx.fr"
src="https://analytics.crvx.fr/js/script.js"
></script>
</div>
</template>

Expand All @@ -93,17 +101,18 @@ import { mapState } from "vuex";
import config from "@/config";
import axios, { AxiosResponse } from "axios";
type HealthResponse = { success: boolean; version: string };
type HealthResponse = { success: boolean; version: string; demo: boolean };
export default Vue.extend({
data: () => ({ config, version: "" }),
data: () => ({ config, version: "", isDemo: false }),
computed: {
...mapState(["number", "errors"]),
},
async created() {
const res: AxiosResponse<HealthResponse> = await axios.get(config.apiUrl);
this.version = res.data.version;
this.isDemo = res.data.demo;
},
});
</script>
2 changes: 2 additions & 0 deletions web/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type healthResponse struct {
Success bool `json:"success"`
Version string `json:"version"`
Commit string `json:"commit"`
Demo bool `json:"demo"`
}

// @ID getAllNumbers
Expand Down Expand Up @@ -183,5 +184,6 @@ func healthHandler(c *gin.Context) {
Success: true,
Version: build.Version,
Commit: build.Commit,
Demo: build.IsDemo(),
})
}
3 changes: 3 additions & 0 deletions web/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,9 @@ var doc = `{
"commit": {
"type": "string"
},
"demo": {
"type": "boolean"
},
"success": {
"type": "boolean"
},
Expand Down
3 changes: 3 additions & 0 deletions web/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,9 @@
"commit": {
"type": "string"
},
"demo": {
"type": "boolean"
},
"success": {
"type": "boolean"
},
Expand Down
2 changes: 2 additions & 0 deletions web/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ definitions:
properties:
commit:
type: string
demo:
type: boolean
success:
type: boolean
version:
Expand Down
2 changes: 1 addition & 1 deletion web/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func TestApi(t *testing.T) {
body, _ := ioutil.ReadAll(res.Body)

assert.Equal(t, 200, res.Result().StatusCode)
assert.Equal(t, "{\"success\":true,\"version\":\"dev\",\"commit\":\"dev\"}", string(body))
assert.Equal(t, `{"success":true,"version":"dev","commit":"dev","demo":false}`, string(body))
})

t.Run("404 error - /api/notfound", func(t *testing.T) {
Expand Down

0 comments on commit af11276

Please sign in to comment.