From 9a0909ad868cdcf033d39555d2a4729dd9b93413 Mon Sep 17 00:00:00 2001 From: gvidoou Date: Fri, 15 Nov 2024 18:57:43 +0200 Subject: [PATCH 1/2] Adding Stape api keys from headers --- template.js | 12 +++------ template.tpl | 76 +++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 59 insertions(+), 29 deletions(-) diff --git a/template.js b/template.js index fd5f5d2..701f4b6 100644 --- a/template.js +++ b/template.js @@ -66,19 +66,15 @@ if (data.type === 'page_view') { data.gtmOnSuccess(); } else { - const containerKey = data.containerKey.split(':'); - const containerZone = containerKey[0]; - const containerIdentifier = containerKey[1]; - const containerApiKey = containerKey[2]; - const containerDefaultDomainEnd = containerKey[3] || 'io'; + const containerIdentifier = getRequestHeader('x-gtm-identifier'); + const defaultDomain = getRequestHeader('x-gtm-default-domain'); + const containerApiKey = getRequestHeader('x-gtm-api-key'); let requestUrl = 'https://' + enc(containerIdentifier) + '.' + - enc(containerZone) + - '.stape.' + - enc(containerDefaultDomainEnd) + + enc(defaultDomain) + '/stape-api/' + enc(containerApiKey) + '/v1/rakuten/auth-proxy'; diff --git a/template.tpl b/template.tpl index ad5a13b..ae97549 100644 --- a/template.tpl +++ b/template.tpl @@ -52,18 +52,6 @@ ___TEMPLATE_PARAMETERS___ "name": "conversionGroup", "groupStyle": "NO_ZIPPY", "subParams": [ - { - "type": "TEXT", - "name": "containerKey", - "displayName": "Stape Container API Key", - "simpleValueType": true, - "valueValidators": [ - { - "type": "NON_EMPTY" - } - ], - "help": "It can be found in the detailed view of the container inside your \u003ca href\u003d\"https://app.stape.io/container/\" target\u003d\"_blank\"\u003eStape account\u003c/a\u003e.\n\u003cbr\u003e\u003cbr\u003e\nBecause of how Rakuten Affiliate API authentication works, it can\u0027t be fully functional on sGTM. That\u0027s why this tag requires working on \u003ca href\u003d\"https://stape.io/gtm-server-hosting\" target\u003d\"_blank\"\u003eStape hosting\u003c/a\u003e.\n\u003cbr\u003e\nIf it will be possible in the future to use only sGTM for authentication we will update this tag to support any hosting." - }, { "type": "TEXT", "name": "mid", @@ -256,7 +244,12 @@ if (data.type === 'page_view') { }; if (rakutenSiteIdValue) { - setCookie('rakuten_site_id', makeString(rakutenSiteIdValue), options, false); + setCookie( + 'rakuten_site_id', + makeString(rakutenSiteIdValue), + options, + false + ); setCookie( 'rakuten_time_entered', makeString(Math.round(getTimestampMillis() / 1000)), @@ -280,19 +273,15 @@ if (data.type === 'page_view') { data.gtmOnSuccess(); } else { - const containerKey = data.containerKey.split(':'); - const containerZone = containerKey[0]; - const containerIdentifier = containerKey[1]; - const containerApiKey = containerKey[2]; - const containerDefaultDomainEnd = containerKey[3] || 'io'; + const containerIdentifier = getRequestHeader('x-gtm-identifier'); + const defaultDomain = getRequestHeader('x-gtm-default-domain'); + const containerApiKey = getRequestHeader('x-gtm-api-key'); let requestUrl = 'https://' + enc(containerIdentifier) + '.' + - enc(containerZone) + - '.stape.' + - enc(containerDefaultDomainEnd) + + enc(defaultDomain) + '/stape-api/' + enc(containerApiKey) + '/v1/rakuten/auth-proxy'; @@ -463,6 +452,51 @@ ___SERVER_PERMISSIONS___ "string": "referer" } ] + }, + { + "type": 3, + "mapKey": [ + { + "type": 1, + "string": "headerName" + } + ], + "mapValue": [ + { + "type": 1, + "string": "x-gtm-identifier" + } + ] + }, + { + "type": 3, + "mapKey": [ + { + "type": 1, + "string": "headerName" + } + ], + "mapValue": [ + { + "type": 1, + "string": "x-gtm-default-domain" + } + ] + }, + { + "type": 3, + "mapKey": [ + { + "type": 1, + "string": "headerName" + } + ], + "mapValue": [ + { + "type": 1, + "string": "x-gtm-api-key" + } + ] } ] } From dd2b91098af5a3f5dec9b331a6d4de4de9679bd0 Mon Sep 17 00:00:00 2001 From: gvidoou Date: Mon, 18 Nov 2024 12:33:51 +0200 Subject: [PATCH 2/2] updated metadata --- metadata.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/metadata.yaml b/metadata.yaml index 439ee2f..ab01ff6 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -1,5 +1,7 @@ homepage: "https://stape.io/" versions: + - sha: 9a0909ad868cdcf033d39555d2a4729dd9b93413 + changeNotes: Getting Stape API key from headers. - sha: bc3ef477cb3fc0ca8d916001868312ef4cc3166d changeNotes: Added fallback for site id. - sha: 570e9421198fb4520e2ed3ab83f63c98e3193aa8