Skip to content

Commit

Permalink
fix code block
Browse files Browse the repository at this point in the history
  • Loading branch information
flashdesignory committed Oct 9, 2023
1 parent 4427da4 commit ddb1aef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/third-parties/google-analytics/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"action": "append"
},
{
"code": "window.dataLayer=window.dataLayer||[];window.gtag=function gtag(){window.dataLayer.push(arguments);};gtag('js',new Date());gtag('config','${args.id}')",
"code": "window.dataLayer=window.dataLayer||[];window.gtag=function gtag(){window.dataLayer.push(arguments);};gtag('js',new Date());gtag('config','{{id}}')",
"strategy": "worker",
"location": "head",
"action": "append"
Expand Down
11 changes: 10 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export function formatUrl(
return newUrl.toString();
}

export function formatCode(code: string, args?: Inputs) {
return code.replace(/{{(.*?)}}/g, (match) => {
return args?.[match.split(/{{|}}/).filter(Boolean)[0]];
});
}

// Construct HTML element and include all default attributes and user-inputted attributes
export function createHtml(
element: string,
Expand Down Expand Up @@ -133,7 +139,10 @@ export function formatData(data: Data, args: Inputs) {
...script,
url: formatUrl(script.url, script.params, scriptUrlParamInputs),
}
: script;
: {
...script,
code: formatCode(script.code, scriptUrlParamInputs),
};
})
: null,
};
Expand Down

0 comments on commit ddb1aef

Please sign in to comment.