Last active
June 27, 2023 20:06
-
-
Save ericakfranz/d6919e0a750eeadaa2d94ef7d75d5140 to your computer and use it in GitHub Desktop.
OptinMonster Custom Smart Tag to capture a specific query arg.
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
const queryString = window.location.search; // capture all query args | |
const urlParams = new URLSearchParams(queryString); // parse parameters | |
const paramName = 'utm_medium'; // create variable to re-use | |
const medium = urlParams.get(paramName); // call our specific parameter | |
document.addEventListener('om.Dtr.init', function(event) { | |
// Registers {{query_arg}} smart tag that outputs a specific query arg from the current page. | |
event.detail.Dtr.setCustomVariable('query_arg', '?' + paramName + '=' + medium); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment