Created
August 24, 2025 14:04
-
-
Save zionskynet/ae1b71f9edeec84496c3c4408beb41db to your computer and use it in GitHub Desktop.
Voluum and GTM Events Tracking Integration JavaScript Code. This code will send a add_to_cart, begin_checkout and purchase events to your Voluum tracker. Make sure your Voluum events have appropriate names.
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
| <!-- page view --> | |
| <script> | |
| // init user data | |
| (function () { | |
| try { | |
| var url = new URL(window.document.location.href), | |
| utmMedium = url.searchParams.get('utm_medium'), | |
| xoClickId = url.searchParams.get('utm_term'); | |
| if (utmMedium === 'xo' && xoClickId) { | |
| localStorage.setItem('utmMedium', utmMedium); | |
| localStorage.setItem('xoClickId', xoClickId); | |
| } | |
| } catch(e) { | |
| console.log(e); | |
| } | |
| })(); | |
| </script> | |
| <!-- page view/ --> | |
| <!-- add to cart --> | |
| <script> | |
| (function () { | |
| function getPostbackURL() { | |
| try { | |
| var utmMedium = localStorage.getItem('utmMedium'); | |
| var xoClickId = localStorage.getItem('xoClickId'); | |
| if (utmMedium === 'xo' && xoClickId) { | |
| return 'https://your-voluum.domain/postback?cid='+xoClickId; | |
| } | |
| } catch(e) { | |
| console.log(e); | |
| } | |
| } | |
| if (getPostbackURL()) { | |
| navigator.sendBeacon(getPostbackURL()+'&et=add_to_cart'); | |
| } | |
| })(); | |
| </script> | |
| <!-- add to cart/ --> | |
| <!-- begin checkout --> | |
| <script> | |
| (function () { | |
| function getPostbackURL() { | |
| try { | |
| var utmMedium = localStorage.getItem('utmMedium'); | |
| var xoClickId = localStorage.getItem('xoClickId'); | |
| if (utmMedium === 'xo' && xoClickId) { | |
| return 'https://your-voluum.domain/postback?cid='+xoClickId; | |
| } | |
| } catch(e) { | |
| console.log(e); | |
| } | |
| } | |
| if (getPostbackURL()) { | |
| navigator.sendBeacon(getPostbackURL()+'&et=begin_checkout'); | |
| } | |
| })(); | |
| </script> | |
| <!-- begin checkout/ --> | |
| <!-- purchase --> | |
| <script> | |
| (function () { | |
| function getPostbackURL() { | |
| try { | |
| var utmMedium = localStorage.getItem('utmMedium'); | |
| var xoClickId = localStorage.getItem('xoClickId'); | |
| if (utmMedium === 'xo' && xoClickId) { | |
| return 'https://your-voluum.domain/postback?cid='+xoClickId; | |
| } | |
| } catch(e) { | |
| console.log(e); | |
| } | |
| } | |
| if (getPostbackURL()) { | |
| var url = getPostbackURL()+'&et=purchase'; | |
| try { | |
| // use your value or GTM {variable} for "price" | |
| var price = document.querySelector('.__total_price').innerText; | |
| price = parseFloat(price.replace(/[^\d.-]/g, '')); | |
| url += '&payout='+price; | |
| } catch(e) { | |
| console.log('no price'); | |
| } | |
| navigator.sendBeacon(url); | |
| } | |
| })(); | |
| </script> | |
| <!-- purchase/ --> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read full article about Voluum+GTM postbacks integration before using this code.