Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docker): add support for Google Tag Manager #5130

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ docker run -d -p 80:8080 -e BASE_URL=/swagger-editor swaggerapi/swagger-editor
docker run -d -p 80:80 -e PORT=80 swaggerapi/swagger-editor
```

* You can specify Google Tag Manager ID via `GTM` variable for tracking the usage of the swagger-editor.

```
docker run -d -p 80:8080 -e GTM=GTM-XXXXXX swaggerapi/swagger-editor
```

You can also customize the different endpoints used by the Swagger Editor with the following environment variables. For instance, this can be useful if you have your own Swagger generator server:

Environment variable | Default value
Expand Down
8 changes: 8 additions & 0 deletions docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ if [[ "${URL_OAS3_GENERATOR}" ]]; then
fi
fi

## Adding Google Tag Manager if GTM is set
if [[ "${GTM}" ]]; then
GTM_SCRIPT="<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','${GTM}');</script>"
GTM_NOSCRIPT="<noscript><iframe src=\"https://www.googletagmanager.com/ns.html?id=${GTM}\" height=\"0\" width=\"0\" style=\"display:none;visibility:hidden\"></iframe></noscript>"
sed -i "s~<!-- Google Tag Manager -->~$GTM_SCRIPT~" $INDEX_FILE
sed -i "s~<!-- Google Tag Manager (noscript) -->~$GTM_NOSCRIPT~" $INDEX_FILE
fi

## Gzip after replacements
#find /usr/share/nginx/html/ -type f -regex ".*\.\(html\|js\|css\)" -exec sh -c "gzip < {} > {}.gz" \;
#
Expand Down
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<head>
<meta charset="UTF-8">
<title>Swagger Editor</title>
<!-- Google Tag Manager -->
<style>
* {
box-sizing: border-box;
Expand Down Expand Up @@ -44,6 +45,7 @@
</head>

<body>
<!-- Google Tag Manager (noscript) -->
<div id="swagger-editor"></div>
<script src="./dist/swagger-editor-bundle.js"> </script>
<script src="./dist/swagger-editor-standalone-preset.js"> </script>
Expand Down
Loading