Expand my Community achievements bar.

Google Ads - Page view call need to add "href" or need to push new url in Page Url

Avatar

Level 4

Hello,

 

1. When user click on Login button,

2. it will open new tab (login page).

 

On first step, Google Ads page view call will be triggered, in this call i want add href url (step 2) or need to update the defalut page Url. 
How can we do this?

 

Google ads code :- 

<script async src="https://www.googletagmanager.com/gtag/js?id=AW-xxxxxxx">
</script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);}
gtag('js', new Date()); gtag('config', 'AW-xxxxxxx'); </script>


login button HTML code:- 
<a class="btn btn--online-banking theme-one--color-01" data-cmp-event="{&quot;componentName&quot;:&quot;&quot;,&quot;componentID&quot;:&quot;/content/plus/jcr:content/navigation/onlinebankingbutton&quot;,&quot;componentType&quot;:&quot;Online banking Button&quot;,&quot;componentArea&quot;:&quot;navigation&quot;,&quot;elementName&quot;:null,&quot;actionLabel&quot;:&quot;Login&quot;,&quot;actionType&quot;:&quot;buttonClick&quot;}" href="https://mmmm.come/hhh" target="_blank" title="Login Banking">
<span class="btn-value" data-caption-mobile="Login" data-caption="Login"></span>
</a>

3 Replies

Avatar

Community Advisor

HI @reddy_y-11 

I think your question should rather be in this forum: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-platform/bd-p/adobe-experience-pla...

 

1) In general, I think your page view google script should be loaded anyway and not just upon click?

2) upon click, you will need a click handler that listens to your specific item's click event i.e., a custom code action in Launch to achieve this, as described here.

Bascially, you enrich the clicked URL with your new parameter and redirect the browser to the updated URL. Important is also the preventDefault to suppress the original navigation that would have been caused by the link URL.

 

 

 

// global click handler
window.addEventListener("click", function(e) {

    // in here, you may need additional checks to make sure the code is not
    // executed on every link click but only the one you are interested in.
    // e.g., by using if (e.target.matches("<my button selector>")) { ... }
    if (e.target.matches("button.btn--online-banking")) {
        var href = e.target.getAttribute("href");
        if(href) {

            // append a new query parameter to the URL
            const url = new URL(href);
            url.searchParams.set("newparam", "newvalue")

            // redirect the browser tab
            location.href = url.href;

            // stop the original browser click handler
            e.preventDefault();
        }
    }
});

 

 

Cheers from Switzerland!

Avatar

Community Advisor

Hi @reddy_y-11 

I don't get it, are you trying to send href as an additional parameter in the google adds page view call?

If yes, then you can modify config API to pass additional parameters in the page view call do that however you need to extract the href on click of a button. You can use example code shared by @bjoern__koth to achieve this and modify your google code script by adding href key value pairs

<script async src="https://www.googletagmanager.com/gtag/js?id=AW-xxxxxxx">
</script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);}
gtag('js', new Date()); gtag('config', 'AW-xxxxxxx',  {
  'href': href
}); </script>

But my question is why are you trying to send href value in a page load call of google ads base script on click of a button, you can use conversion pixels instead.

 

for more details on gtag API check this.

Avatar

Community Advisor

Hi @Ankit_Chaudhary 

sounds like it is more to be added upon user interaction and not on page load, correct @reddy_y-11 ?

Cheers from Switzerland!