Skip to content

Commit

Permalink
Merge pull request #5 from stape-io/get_api_url_from_headers
Browse files Browse the repository at this point in the history
Adding Stape api keys from headers
  • Loading branch information
Bukashk0zzz authored Nov 18, 2024
2 parents 5e49baa + dd2b910 commit 210e089
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 29 deletions.
2 changes: 2 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 4 additions & 8 deletions template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
76 changes: 55 additions & 21 deletions template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)),
Expand All @@ -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';
Expand Down Expand Up @@ -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"
}
]
}
]
}
Expand Down

0 comments on commit 210e089

Please sign in to comment.