AdWords
5.2K members online now
5.2K members online now
Use AdWords conversion tracking and reporting to measure your results. Have a question about Google Analytics? Post it here, on the Google Analytics Community!
Guide Me
star_border
Reply

Onclick Command Button Tracking for Dynamically created URLs

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hopefully someone in the Community can help!

 

I'm currently creating "clicks as conversions" on my site. The first part of the code is easy, but I'm running into an issue with the "onclick".

 

Here is a sample page (NOTE: the button click code is NOT on here right now).

 

https://agileacademy.ca.com/courses/certified-scrummaster

 

If you select any of the radio buttons and then click "REGISTER", you are sent to the URL for that specific class location. The URL is created dynamically, it's not hard-coded into the button.

 

The button is created in CSS (Drupal).

 

How can I add the "onclick command" around a dynamically generated URL? Is there a way to add the command into CSS?

 

Thanks!

-Sue

 

2 Expert replyverified_user

Onclick Command Button Tracking for Dynamically created URLs

Top Contributor
# 2
Top Contributor

Hi Sue L,

That's a tough one. I can't quite tell what's going on with the page. It seems to me somewhere is a script that gets called when you click on the "Register" button. CSS doesn't do that by itself.

Ok, when you click on one of the radio buttons, it updates the href of the link that's within "<div class="course-event-wrapper-button">". That's how it determines which page to load when you click on the Register button. It's not really a button, it's a link made to look something like a button using CSS.

You should be able to do this:

<a class="course-event-button" target="_blank" href="http://www.cvent.com/d/2vqspc/4W" onclick="goog_report_conversion(this.href)">Register Now</a>

 

Best of Luck!

 

Pete

 

petebardo -- Deadhead doing AdWords

Onclick Command Button Tracking for Dynamically created URLs

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Thanks! I try it out. 

 

Yes - each URL is generated on the fly based on the date the user picks, which makes this not very clear-cut. Smiley Happy

 

But I will definitely try that out.

 

-Sue

Onclick Command Button Tracking for Dynamically created URLs

Rising Star
# 4
Rising Star

@sue l

 

Another option would be to setup a click listener in Google Tag Manager for urls containing www.cvent.com. 

https://support.google.com/tagmanager/answer/6106961?hl=en#Click

Onclick Command Button Tracking for Dynamically created URLs

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

Thanks! I'm actually currently testing this idea, using the * at the end of the cvent link to see if that triggers. Do you see any holes? I guess it takes a while for Google to verify so I don't know if it's working yet or not.

 

 

 

<?php if (!empty($title)): ?>
  <h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
  <div <?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"';  } ?> itemtype="http://schema.org/EducationEvent" itemscope="">
    <input class="course-event-selection" type="radio" name="event" value="<?php print $variables['view']->result[$id]->nid; ?>">
    <?php print $row; ?>
  </div>
<?php endforeach; ?>
<div class="course-event-wrapper-button">
  <a class="course-event-button" target="_blank" onclick="goog_report_conversion ('http://www.cvent.com/*')" href="#">Register Now</a>
</div>
<div class="course-event-display-cost"></div>
<div class="course-event-display-cost-adj"></div>
<div class="course-event-early-bird"></div> 

Onclick Command Button Tracking for Dynamically created URLs

Rising Star
# 6
Rising Star

@sue l

 

I'm not a coder, but I don't think the * works as a wild card in that instance. I'm thinking you'd have to do it in RegEx, and even then I'm not certain that would work.  Not my realm of expertise though.

I know it can be done in Google Tag Manager.  You just set up a  trigger that uses the "Click URL" and "contains" options, and then put cvent.com in the field. It also has a preview/debug mode to see if your tag fires under the condition(s) you've set without waiting for an actual conversion to come in.  https://support.google.com/tagmanager/answer/6107056?hl=en