all repos — caroster @ d73b3aab4ab278fb55f4aa9224a110320bffb6a6

[Octree] Group carpool to your event https://caroster.io

⚡️Add Google Analytics tag management #37
Tim Izzo tim@octree.ch
Wed, 08 Jul 2020 14:27:24 +0000
commit

d73b3aab4ab278fb55f4aa9224a110320bffb6a6

parent

4d743f74cfd3769e3d91164f9851ccc75405e814

A api/settings/config/routes.json

@@ -0,0 +1,28 @@

+{ + "routes": [ + { + "method": "GET", + "path": "/settings", + "handler": "settings.find", + "config": { + "policies": [] + } + }, + { + "method": "PUT", + "path": "/settings", + "handler": "settings.update", + "config": { + "policies": [] + } + }, + { + "method": "DELETE", + "path": "/settings", + "handler": "settings.delete", + "config": { + "policies": [] + } + } + ] +}
A api/settings/controllers/settings.js

@@ -0,0 +1,8 @@

+'use strict'; + +/** + * Read the documentation (https://strapi.io/documentation/v3.x/concepts/controllers.html#core-controllers) + * to customize this controller + */ + +module.exports = {};
A api/settings/documentation/1.0.0/settings.json

@@ -0,0 +1,340 @@

+{ + "paths": { + "/settings": { + "get": { + "deprecated": false, + "description": "Find all the settings's records", + "responses": { + "200": { + "description": "Retrieve settings document(s)", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Settings" + } + } + } + } + }, + "403": { + "description": "Forbidden", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "404": { + "description": "Not found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + }, + "summary": "", + "tags": [ + "Settings" + ], + "parameters": [ + { + "name": "_limit", + "in": "query", + "required": false, + "description": "Maximum number of results possible", + "schema": { + "type": "integer" + }, + "deprecated": false + }, + { + "name": "_sort", + "in": "query", + "required": false, + "description": "Sort according to a specific field.", + "schema": { + "type": "string" + }, + "deprecated": false + }, + { + "name": "_start", + "in": "query", + "required": false, + "description": "Skip a specific number of entries (especially useful for pagination)", + "schema": { + "type": "integer" + }, + "deprecated": false + }, + { + "name": "=", + "in": "query", + "required": false, + "description": "Get entries that matches exactly your input", + "schema": { + "type": "string" + }, + "deprecated": false + }, + { + "name": "_ne", + "in": "query", + "required": false, + "description": "Get records that are not equals to something", + "schema": { + "type": "string" + }, + "deprecated": false + }, + { + "name": "_lt", + "in": "query", + "required": false, + "description": "Get record that are lower than a value", + "schema": { + "type": "string" + }, + "deprecated": false + }, + { + "name": "_lte", + "in": "query", + "required": false, + "description": "Get records that are lower than or equal to a value", + "schema": { + "type": "string" + }, + "deprecated": false + }, + { + "name": "_gt", + "in": "query", + "required": false, + "description": "Get records that are greater than a value", + "schema": { + "type": "string" + }, + "deprecated": false + }, + { + "name": "_gte", + "in": "query", + "required": false, + "description": "Get records that are greater than or equal a value", + "schema": { + "type": "string" + }, + "deprecated": false + }, + { + "name": "_contains", + "in": "query", + "required": false, + "description": "Get records that contains a value", + "schema": { + "type": "string" + }, + "deprecated": false + }, + { + "name": "_containss", + "in": "query", + "required": false, + "description": "Get records that contains (case sensitive) a value", + "schema": { + "type": "string" + }, + "deprecated": false + }, + { + "name": "_in", + "in": "query", + "required": false, + "description": "Get records that matches any value in the array of values", + "schema": { + "type": "array", + "items": { + "type": "string" + } + }, + "deprecated": false + }, + { + "name": "_nin", + "in": "query", + "required": false, + "description": "Get records that doesn't match any value in the array of values", + "schema": { + "type": "array", + "items": { + "type": "string" + } + }, + "deprecated": false + } + ] + }, + "put": { + "deprecated": false, + "description": "Update a single settings record", + "responses": { + "200": { + "description": "Retrieve settings document(s)", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Settings" + } + } + } + }, + "403": { + "description": "Forbidden", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "404": { + "description": "Not found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + }, + "summary": "", + "tags": [ + "Settings" + ], + "requestBody": { + "description": "", + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/NewSettings" + } + } + } + }, + "parameters": [] + }, + "delete": { + "deprecated": false, + "description": "Delete a single settings record", + "responses": { + "200": { + "description": "deletes a single settings based on the ID supplied", + "content": { + "application/json": { + "schema": { + "type": "integer", + "format": "int64" + } + } + } + }, + "403": { + "description": "Forbidden", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "404": { + "description": "Not found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + }, + "summary": "", + "tags": [ + "Settings" + ], + "parameters": [] + } + } + }, + "components": { + "schemas": { + "Settings": { + "required": [ + "id" + ], + "properties": { + "id": { + "type": "string" + }, + "gtm_id": { + "type": "string" + } + } + }, + "NewSettings": { + "properties": { + "gtm_id": { + "type": "string" + } + } + } + } + }, + "tags": [ + { + "name": "Settings" + } + ] +}
A api/settings/models/settings.js

@@ -0,0 +1,8 @@

+'use strict'; + +/** + * Read the documentation (https://strapi.io/documentation/v3.x/concepts/models.html#lifecycle-hooks) + * to customize this model + */ + +module.exports = {};
A api/settings/models/settings.settings.json

@@ -0,0 +1,17 @@

+{ + "kind": "singleType", + "collectionName": "settings", + "info": { + "name": "settings" + }, + "options": { + "increments": true, + "timestamps": true + }, + "attributes": { + "gtm_id": { + "type": "string", + "regex": "GTM-.*" + } + } +}
A api/settings/services/settings.js

@@ -0,0 +1,8 @@

+'use strict'; + +/** + * Read the documentation (https://strapi.io/documentation/v3.x/concepts/services.html#core-services) + * to customize this service + */ + +module.exports = {};
M app/src/App.jsapp/src/App.js

@@ -8,7 +8,12 @@ import CssBaseline from '@material-ui/core/CssBaseline';

import Router from './Router'; import theme from './theme'; -const models = [{name: 'events'}, {name: 'cars'}, {name: 'pages'}]; +const models = [ + {name: 'events'}, + {name: 'cars'}, + {name: 'pages'}, + {name: 'settings', singleType: true, init: true}, +]; const App = () => { return (
M app/src/Router.jsapp/src/Router.js

@@ -1,5 +1,6 @@

import React from 'react'; import {BrowserRouter, Route, Switch} from 'react-router-dom'; +import useGTM from './hooks/useGTM'; // Pages import Home from './pages/Home';

@@ -7,6 +8,7 @@ import Event from './pages/Event';

import NotFound from './pages/NotFound'; const Router = () => { + useGTM(); return ( <BrowserRouter> <Switch>
A app/src/hooks/useGTM.js

@@ -0,0 +1,36 @@

+import {useEffect} from 'react'; +import {useStrapi} from 'strapi-react-context'; + +const getHeadScript = gtmId => `(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','${gtmId}'); +`; + +const getBodyScript = gtmId => `<iframe src="https://www.googletagmanager.com/ns.html?id=${gtmId}" +height="0" width="0" style="display:none;visibility:hidden"></iframe> +`; + +export default () => { + const strapi = useStrapi(); + + if (process.env.NODE_ENV !== 'production') return null; + + useEffect(() => { + if (strapi.stores.settings) { + const [{gtm_id: gtmId}] = strapi.stores.settings; + if (gtmId) loadGTM(gtmId); + } + }, [strapi.stores.settings]); + + const loadGTM = gtmId => { + const headScript = document.createElement('script'); + headScript.innerHTML = getHeadScript(gtmId); + const bodyScript = document.createElement('noscript'); + bodyScript.innerHTML = getBodyScript(gtmId); + + document.head.insertBefore(headScript, document.head.childNodes[0]); + document.body.insertBefore(bodyScript, document.body.childNodes[0]); + }; +};
M config/permissions.jsonconfig/permissions.json

@@ -15,6 +15,10 @@ },

{ "name": "page", "actions": ["find", "findone"] + }, + { + "name": "settings", + "actions": ["find"] } ] }
M extensions/documentation/documentation/1.0.0/full_documentation.jsonextensions/documentation/documentation/1.0.0/full_documentation.json

@@ -14,7 +14,7 @@ "license": {

"name": "Apache 2.0", "url": "https://www.apache.org/licenses/LICENSE-2.0.html" }, - "x-generation-date": "06/30/2020 3:56:41 PM" + "x-generation-date": "07/08/2020 12:13:00 PM" }, "x-strapi-config": { "path": "/documentation",

@@ -1578,6 +1578,313 @@ }

} ] } + }, + "/settings": { + "get": { + "deprecated": false, + "description": "Find all the settings's records", + "responses": { + "200": { + "description": "Retrieve settings document(s)", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Settings" + } + } + } + } + }, + "403": { + "description": "Forbidden", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "404": { + "description": "Not found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + }, + "summary": "", + "tags": [ + "Settings" + ], + "parameters": [ + { + "name": "_limit", + "in": "query", + "required": false, + "description": "Maximum number of results possible", + "schema": { + "type": "integer" + }, + "deprecated": false + }, + { + "name": "_sort", + "in": "query", + "required": false, + "description": "Sort according to a specific field.", + "schema": { + "type": "string" + }, + "deprecated": false + }, + { + "name": "_start", + "in": "query", + "required": false, + "description": "Skip a specific number of entries (especially useful for pagination)", + "schema": { + "type": "integer" + }, + "deprecated": false + }, + { + "name": "=", + "in": "query", + "required": false, + "description": "Get entries that matches exactly your input", + "schema": { + "type": "string" + }, + "deprecated": false + }, + { + "name": "_ne", + "in": "query", + "required": false, + "description": "Get records that are not equals to something", + "schema": { + "type": "string" + }, + "deprecated": false + }, + { + "name": "_lt", + "in": "query", + "required": false, + "description": "Get record that are lower than a value", + "schema": { + "type": "string" + }, + "deprecated": false + }, + { + "name": "_lte", + "in": "query", + "required": false, + "description": "Get records that are lower than or equal to a value", + "schema": { + "type": "string" + }, + "deprecated": false + }, + { + "name": "_gt", + "in": "query", + "required": false, + "description": "Get records that are greater than a value", + "schema": { + "type": "string" + }, + "deprecated": false + }, + { + "name": "_gte", + "in": "query", + "required": false, + "description": "Get records that are greater than or equal a value", + "schema": { + "type": "string" + }, + "deprecated": false + }, + { + "name": "_contains", + "in": "query", + "required": false, + "description": "Get records that contains a value", + "schema": { + "type": "string" + }, + "deprecated": false + }, + { + "name": "_containss", + "in": "query", + "required": false, + "description": "Get records that contains (case sensitive) a value", + "schema": { + "type": "string" + }, + "deprecated": false + }, + { + "name": "_in", + "in": "query", + "required": false, + "description": "Get records that matches any value in the array of values", + "schema": { + "type": "array", + "items": { + "type": "string" + } + }, + "deprecated": false + }, + { + "name": "_nin", + "in": "query", + "required": false, + "description": "Get records that doesn't match any value in the array of values", + "schema": { + "type": "array", + "items": { + "type": "string" + } + }, + "deprecated": false + } + ] + }, + "put": { + "deprecated": false, + "description": "Update a single settings record", + "responses": { + "200": { + "description": "Retrieve settings document(s)", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Settings" + } + } + } + }, + "403": { + "description": "Forbidden", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "404": { + "description": "Not found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + }, + "summary": "", + "tags": [ + "Settings" + ], + "requestBody": { + "description": "", + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/NewSettings" + } + } + } + }, + "parameters": [] + }, + "delete": { + "deprecated": false, + "description": "Delete a single settings record", + "responses": { + "200": { + "description": "deletes a single settings based on the ID supplied", + "content": { + "application/json": { + "schema": { + "type": "integer", + "format": "int64" + } + } + } + }, + "403": { + "description": "Forbidden", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "404": { + "description": "Not found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + }, + "summary": "", + "tags": [ + "Settings" + ], + "parameters": [] + } } }, "components": {

@@ -1826,6 +2133,26 @@ ]

} } }, + "Settings": { + "required": [ + "id" + ], + "properties": { + "id": { + "type": "string" + }, + "gtm_id": { + "type": "string" + } + } + }, + "NewSettings": { + "properties": { + "gtm_id": { + "type": "string" + } + } + }, "Error": { "required": [ "code",

@@ -1859,6 +2186,9 @@ "name": "Event"

}, { "name": "Page" + }, + { + "name": "Settings" } ] }