Good morning my dears I've been banging my head for a few days, thank you in advance if you can help me, please. sorry my english
Today, when a person arrives on my site from facebook ads, they arrive with a parameter showing which ad brought them:
site.com/?src=ad1
I have a code in the footer of my site that adds this src parameter to the purchase links spread across the page, so I can check which ad converted the most into sales:
<script type="text/javascript">
const urlParams= new URLSearchParams(window.location.search);
const myParam = urlParams.get('src');
const allLinks = document.getElementsByTagName('a');
for (var i = 0; i < allLinks.length; i++) {
allLinks[i].href = allLinks[i].href + '&src=' + myParam;
}
</script>
My question is the following, many visits come through google articles, so I wanted to add some parameter in the url and consequently in the purchase links, which I could know which article in question brings more sales. I thought a plausible solution would be to add the POST ID as a parameter. Something like that:
site.com/post12345/?src=ad1&id=12345
Would it be possible to do this? What code should I add to my site and what modification should I make to my footer code (shown above) for this to work?
Thanks in advance!! If you have a better solution, I'd appreciate it. I'm a programming noob!