Skip to content

Commit

Permalink
Merge pull request #62 from foomo/hotjar
Browse files Browse the repository at this point in the history
feat(provider/hotjar): add provider
  • Loading branch information
franklinkim authored Nov 7, 2024
2 parents 427201c + 5c56cea commit 5082d82
Show file tree
Hide file tree
Showing 15 changed files with 282 additions and 268 deletions.
43 changes: 17 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Add a `sesamy.yaml` configuration

```yaml
# yaml-language-server: $schema=https://raw.githubusercontent.com/foomo/sesamy-cli/v0.4.1/sesamy.yaml
# yaml-language-server: $schema=sesamy.schema.json
version: '1.0'

# Whether to redact the visitor ip
Expand All @@ -68,49 +69,33 @@ googleApi:
# --- Google Tag Manager settings
googleTagManager:
# The account id
accountId: 6099238525
accountId: '6099238525'
# Web container settings
webContainer:
# The container tag id
tagId: GTM-57BHX34G
# The container id
containerId: 175355532
containerId: '175355532'
# The workspace id that should be used by the api
workspaceId: 23
workspaceId: '23'
# Server container settings
serverContainer:
# The container tag id
tagId: GTM-5NWPR4QW
# The container id
containerId: 175348980
containerId: '175348980'
# The workspace id that should be used by the api
workspaceId: 10
workspaceId: '10'

# --- Google Tag settings
googleTag:
# A tag ID is an identifier that you put on your page to load a given Google tag
tagId: G-PZ5ELRCR31
# Whether a page_view should be sent on initial load
sendPageView: true
# Enable debug mode for all user devices
debugMode: false
# Google Tag Manager web container settings
webContainer:
# Contemplate package config for generated events
packages:
- path: github.com/foomo/sesamy-go/pkg/event
types:
- PageView
- SelectItem
# Google Tag Manager server container settings
serverContainer:
# Contemplate package config for generated events
packages:
- path: github.com/foomo/sesamy-go/pkg/event
types:
- PageView
- SelectItem
# Google Tag Manager web container settings
# Whether a page_view should be sent on initial load
sendPageView: true
# TypeScript settings
typeScript:
# Target directory for generate files
outputPath: path/to/target
Expand Down Expand Up @@ -175,7 +160,6 @@ googleTag:
- ViewPromotion
- WorkingLead


# --- Google Analytics settings
googleAnalytics:
# Enable provider
Expand Down Expand Up @@ -291,13 +275,13 @@ facebook:
apiAccessToken: ''
# Code used to verify that your server events are received correctly by Conversions API
testEventToken: ''
# Google Tag Manager server container settings
# Google Consent settings
googleConsent:
# Enable consent mode
enabled: true
# Consent mode name
mode: ad_storage
# Google Tag Manager server container settings
serverContainer:
# Contemplate package config for generated events
packages:
Expand Down Expand Up @@ -360,6 +344,13 @@ tracify:
- ViewItem
- Purchase

# --- Hotjar
hotjar:
# Enable provider
enabled: true
# Hotjar site id
siteId: 123456

# --- Cookiebot CMP
cookiebot:
# Enable provider
Expand Down
7 changes: 7 additions & 0 deletions cmd/tagmanager/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
emarsysprovider "github.com/foomo/sesamy-cli/pkg/provider/emarsys"
googleanaylticsprovider "github.com/foomo/sesamy-cli/pkg/provider/googleanalytics"
googletagprovider "github.com/foomo/sesamy-cli/pkg/provider/googletag"
hotjarprovider "github.com/foomo/sesamy-cli/pkg/provider/hotjar"
"github.com/foomo/sesamy-cli/pkg/tagmanager"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -60,6 +61,12 @@ func NewWeb(root *cobra.Command) {
}
}

if cfg.Hotjar.Enabled && pkgcmd.Tag(hotjarprovider.Tag, tags) {
if err := hotjarprovider.Web(tm, cfg.Hotjar); err != nil {
return errors.Wrap(err, "failed to provision hotjar provider")
}
}

if cfg.Cookiebot.Enabled && pkgcmd.Tag(cookiebotprovider.Tag, tags) {
if err := cookiebotprovider.Web(tm, cfg.Cookiebot); err != nil {
return errors.Wrap(err, "failed to provision cookiebot provider")
Expand Down
9 changes: 9 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"errors"
"os"
"path"
"reflect"
"strings"
"testing"

testingx "github.com/foomo/go/testing"
Expand All @@ -22,6 +24,13 @@ func TestConfig(t *testing.T) {
require.NoError(t, err)

reflector := new(jsonschema.Reflector)
reflector.RequiredFromJSONSchemaTags = true
reflector.Namer = func(t reflect.Type) string {
if t.Name() == "" {
return t.String()
}
return strings.ReplaceAll(t.PkgPath(), "/", ".") + "." + t.Name()
}
require.NoError(t, reflector.AddGoComments("github.com/foomo/sesamy-cli", "./"))
schema := reflector.Reflect(&config.Config{})
actual, err := json.MarshalIndent(schema, "", " ")
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type Config struct {
Facebook Facebook `json:"facebook" yaml:"facebook"`
// Emarsys provider settings
Emarsys Emarsys `json:"emarsys" yaml:"emarsys"`
// Hotjar provider settings
Hotjar Hotjar `json:"hotjar" yaml:"hotjar"`
// Tracify provider settings
Tracify Tracify `json:"tracify" yaml:"tracify"`
// Umami provider settings
Expand Down
13 changes: 9 additions & 4 deletions pkg/config/emarsys.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import (
)

type Emarsys struct {
Enabled bool `json:"enabled" yaml:"enabled"`
MerchantID string `json:"merchantId" yaml:"merchantId"`
GoogleConsent GoogleConsent `json:"googleConsent" yaml:"googleConsent"`
WebContainer contemplate.Config `json:"webContainer" yaml:"webContainer"`
// Enable provider
Enabled bool `json:"enabled" yaml:"enabled"`
// Emarsys merchant id
MerchantID string `json:"merchantId" yaml:"merchantId"`
// Google Consent settings
GoogleConsent GoogleConsent `json:"googleConsent" yaml:"googleConsent"`
// Google Tag Manager web container settings
WebContainer contemplate.Config `json:"webContainer" yaml:"webContainer"`
// Google Tag Manager server container settings
ServerContainer contemplate.Config `json:"serverContainer" yaml:"serverContainer"`
}
12 changes: 8 additions & 4 deletions pkg/config/googletag.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package config

type GoogleTag struct {
TagID string `json:"tagId" yaml:"tagId"`
DebugMode bool `json:"debugMode" yaml:"debugMode"`
SendPageView bool `json:"sendPageView" yaml:"sendPageView"`
TypeScript TypeScript `json:"typeScript" yaml:"typeScript"`
// A tag ID is an identifier that you put on your page to load a given Google tag
TagID string `json:"tagId" yaml:"tagId"`
// Enable debug mode for all user devices
DebugMode bool `json:"debugMode" yaml:"debugMode"`
// Whether a page_view should be sent on initial load
SendPageView bool `json:"sendPageView" yaml:"sendPageView"`
// TypeScript settings
TypeScript TypeScript `json:"typeScript" yaml:"typeScript"`
}
6 changes: 6 additions & 0 deletions pkg/config/hotjar.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package config

type Hotjar struct {
Enabled bool `json:"enabled" yaml:"enabled"`
SiteID string `json:"siteId" yaml:"siteId"`
}
13 changes: 9 additions & 4 deletions pkg/config/tracify.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import (
)

type Tracify struct {
Enabled bool `json:"enabled" yaml:"enabled"`
Token string `json:"token" yaml:"token"`
CustomerSiteID string `json:"customerSiteId" yaml:"customerSiteId"`
GoogleConsent GoogleConsent `json:"googleConsent" yaml:"googleConsent"`
// Enable provider
Enabled bool `json:"enabled" yaml:"enabled"`
// Tracify token
Token string `json:"token" yaml:"token"`
// Tracify customer site id
CustomerSiteID string `json:"customerSiteId" yaml:"customerSiteId"`
// Google Consent settings
GoogleConsent GoogleConsent `json:"googleConsent" yaml:"googleConsent"`
// Google Tag Manager server container settings
ServerContainer contemplate.Config `json:"serverContainer" yaml:"serverContainer"`
}
8 changes: 8 additions & 0 deletions pkg/provider/hotjar/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package hotjar

const (
Tag = "hotjar"
Name = "Hotjar"
NameSiteID = "Hotjar Site ID"
NameHotjarTag = "Hotjar"
)
31 changes: 31 additions & 0 deletions pkg/provider/hotjar/web.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package hotjar

import (
"github.com/foomo/sesamy-cli/pkg/config"
client "github.com/foomo/sesamy-cli/pkg/provider/hotjar/web/tag"
"github.com/foomo/sesamy-cli/pkg/tagmanager"
commonvariable "github.com/foomo/sesamy-cli/pkg/tagmanager/common/variable"
)

func Web(tm *tagmanager.TagManager, cfg config.Hotjar) error {
{ // create folder
if folder, err := tm.UpsertFolder("Sesamy - " + Name); err != nil {
return err
} else {
tm.SetFolderName(folder.Name)
}
}

{ // setup hotjar
siteID, err := tm.UpsertVariable(commonvariable.NewConstant(NameSiteID, cfg.SiteID))
if err != nil {
return err
}

if _, err = tm.UpsertTag(client.NewHotjar(NameHotjarTag, siteID)); err != nil {
return err
}
}

return nil
}
22 changes: 22 additions & 0 deletions pkg/provider/hotjar/web/tag/hotjar.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package client

import (
"github.com/foomo/sesamy-cli/pkg/tagmanager/web/trigger"
"google.golang.org/api/tagmanager/v2"
)

func NewHotjar(name string, siteID *tagmanager.Variable) *tagmanager.Tag {
ret := &tagmanager.Tag{
FiringTriggerId: []string{trigger.IDAllPages},
Name: name,
Parameter: []*tagmanager.Parameter{
{
Key: "hotjar_site_id",
Type: "template",
Value: "{{" + siteID.Name + "}}",
},
},
Type: "hjtc",
}
return ret
}
1 change: 1 addition & 0 deletions pkg/tagmanager/web/trigger/builtin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package trigger

const (
IDAllPages = "2147479553"
IDInitialization = "2147479573"
IDConsentInitializtion = "2147479572"
)
Loading

0 comments on commit 5082d82

Please sign in to comment.