Created
June 26, 2021 15:59
-
-
Save tiwariayush/b3642261f51dd674ce67038a0179f19a to your computer and use it in GitHub Desktop.
Sandboxed JavaScript to make HTTP request from Google Tag Manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| return function(gtmData, headers, apiUrl) { | |
| const injectScript = require('injectScript'); | |
| const callInWindow = require('callInWindow'); | |
| const log = require('logToConsole'); | |
| const queryPermission = require('queryPermission'); | |
| const httpScriptUrl = 'https://storage.googleapis.com/common-scripts/basicMethods.js'; | |
| const endpoint = apiUrl + '/v1/webhook/facebook_capi/send_event/'; | |
| // check for permisssion | |
| if (queryPermission('inject_script', httpScriptUrl)) { | |
| injectScript(httpScriptUrl, onSuccess, data.gtmOnFailure, endpoint); | |
| } else { | |
| data.gtmOnFailure(); | |
| } | |
| function onSuccess() { | |
| callInWindow('sendRequest', 'POST', endpoint, gtmData, headers); | |
| data.gtmOnSuccess(); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment