Support

Home Forums MailChimp Integration Ticket url to Mailchimp

Ticket url to Mailchimp

Posted: September 25, 2016 at 6:37 am


Railpromo

September 25, 2016 at 6:37 am

Hi team,

Recently I included your solution for sending the event data to Mailchimp (see this post).
Would it also be possible to pass the ticket URL to Mailchimp? I see EE4 comes with the short code [TXN_TICKETS_URL], but then this needs to be included as a function to make its content be linked with a merge var.

Would you be able to give some suggestions to get this done, mainly with respect to the EE-side function?

Maybe there is a general way to pass shortcode content to merge vars?

The purpose of this is to be able to include the ticket mail into the Mailchimp automation flow. This enables to maintain consequent styling through all messages.

Cheers,
Luc


Tony

  • Support Staff

September 26, 2016 at 5:03 am

Hi Luc,

[TXN_TICKETS_URL] generates a link that shows ALL of the tickets assigned to a transaction regardless of weather or not that registration is Approved.

Using the link you are requesting, are you looking to display all the tickets for a transaction or the single individual ticket for the registration the email is for?

You can generate the same output as [TXN_TICKETS_URL] using the same method used in the ticketing add-on:

\ee4-ticketing\EE_Ticketing.class.php around line 571 you’ll see how its done, you would use something like:

$reg_url_link = $registration->reg_url_link();

$query_args = array(
	'ee' => $approved_only ? 'ee-txn-tickets-approved-url' : 'ee-txn-tickets-url',
	'token' => $reg_url_link
);
$txn_tickets_url = add_query_arg( $query_args, get_site_url() );

Then assign $txn_tickets_url to a merge var.

If you want the specific ticket for the registration you’ll need to do a little more work, here is an example that adds the ticket link to the ‘My Events’ section of the EE4 user add-on:

https://gist.github.com/Pebblo/e56f98451d1aa0964717

Rather than assigning the ticket url to $actions['ticket'] you would assign it to a merge var.


Railpromo

October 1, 2016 at 7:19 am

Dear Tony,

Thanks for your swift and elaborate reply.

I take it the call to Mailchimp is only made when a transaction is successfull and the registration is approved. In other words, the value of [TXN_TICKETS_URL], which is also used in the mail template, would only show valid tickets at the time the call to Mailchimp is made and the mergevar is somehow set up – right?

I’m trying to find a similarity in the approach used to get the event date sent to Mailchimp. This is used for that:

function tw_eea_mailchimp_start_date( $subscribe_args, $registration, $EVT_ID ) {
	//Check we have a valid EE Registration
	if( $registration instanceof EE_Registration ) {
		
		//Pull the merge_vars array from $subscribe_args.
		$merge_vars = $subscribe_args['merge_vars'];
		//Pull the datetimes assigned to this ticket that have a start date greater than today.
		$where = array( 'DTT_EVT_start' => array( '>=', current_time( 'mysql' ) ) );
		$datetimes = $registration->ticket()->datetimes( array( $where,	'order_by'=> array('DTT_EVT_start' => 'ASC' ) ) );
		//Use the first datetime.
		$datetime = reset($datetimes);
		//Add the 'EVENTDATE' merge var and use the datetimes start_date for the value.
		$merge_vars['EVENTDATE'] = $datetime->start_date( 'Y-m-d' );
		//Add the merge vars back into the subscriptions args.
		$subscribe_args['merge_vars'] = $merge_vars;
	}
	
	return $subscribe_args;
}
add_filter('FHEE__EE_MCI_Controller__mci_submit_to_mailchimp__subscribe_args', 'tw_eea_mailchimp_start_date', 10, 3);

So for the ticket url I would need something like:

function tw_eea_mailchimp_ticket_url( $subscribe_args, $registration, $EVT_ID ) {
	//Check we have a valid EE Registration
	if( $registration instanceof EE_Registration ) {
	
$reg_url_link = $registration->reg_url_link();

$query_args = array(
	'ee' => $approved_only ? 'ee-txn-tickets-approved-url' : 'ee-txn-tickets-url',
	'token' => $reg_url_link
);
$txn_tickets_url = add_query_arg( $query_args, get_site_url() );

	
		//Pull the merge_vars array from $subscribe_args.
		$merge_vars = $subscribe_args['merge_vars'];

		//Add the 'TICKETURL' merge var
		$merge_vars['TICKETURL'] = $txn_tickets_url;
		//Add the merge vars back into the subscriptions args.
		$subscribe_args['merge_vars'] = $merge_vars;

}

add_filter('FHEE__EE_MCI_Controller__mci_submit_to_mailchimp__subscribe_args', 'tw_eea_mailchimp_ticket_url', 10, 3);

Right?

Cheers,
Luc


Railpromo

October 1, 2016 at 7:26 am

There’s a

	}
	return $subscribe_args;

missing at the end. I’m aware of that. Sorry.

I implemented and tested it, but there’s nothing passed to Mailchimp (the TICKETURL field remains empty).

Did I make an (obvious) mistake?

Best,
Luc


Tony

  • Support Staff

October 4, 2016 at 4:56 am

I take it the call to Mailchimp is only made when a transaction is successfull and the registration is approved.

That depends on your settings.

Go to Event Espresso -> Mailchimp

What is set for the ‘Submit to MailChimp when …’ option?

If you only want that to happen when a registration has been fully approved you would set it to:

registration is completed with an approved status.

However a ticket is not ‘Valid’ unless it is Approved, so if you are checking the users in and scanning the tickets it make no difference if they have the tickets and have not paid… the ticket scan will show the ticket is not valid.

Your code should work, however you have this:

'ee' => $approved_only ? 'ee-txn-tickets-approved-url' : 'ee-txn-tickets-url',

Which basically says, if $approved_only is true, set that value to ‘ee-txn-tickets-approved-url’ otherwise set it to ‘ee-txn-tickets-url’… but you have no $approved_only var.

It depends on how you want to handle the values but I would use:

'ee' => 'ee-txn-tickets-url',

  • This reply was modified 7 years, 6 months ago by  Tony. Reason: Typo


Railpromo

October 4, 2016 at 10:34 am

Dear Tony,

I included the change you proposed, but unfortunately still nothing is passed to Mailchimp.

The setting of the Mailchimp segment is indeed “registration is completed with an approved status.”

However a ticket is not ‘Valid’ unless it is Approved, so if you are checking the users in and scanning the tickets it make no difference if they have the tickets and have not paid… the ticket scan will show the ticket is not valid.

But they don’t get the tickets until paid, right? Assuming the only payment options offered are the on-line payment options, i.e. you can’t do a bank transfer or get an invoice.

Best,
Luc

  • This reply was modified 7 years, 6 months ago by  Tony. Reason: Now = Not


Tony

  • Support Staff

October 5, 2016 at 8:40 am

But they don’t get the tickets until paid, right? Assuming the only payment options offered are the on-line payment options, i.e. you can’t do a bank transfer or get an invoice.

That’s correct, they should not receive the tickets until they have paid (or the registration is Approved).

I included the change you proposed, but unfortunately still nothing is passed to Mailchimp.

Looks like MailChimp doesn’t like the full URLs being passed as merge vars, I get the same problem when testing the above on a test site.

Another option is to just pass over the reg_url_link and build out the ticket URL in mailchimp yourself, for example:


$reg_url_link = $registration->reg_url_link();

$merge_vars['TICKETPARAM'] = $reg_url_link;

You can add that to the same function that adds the event date rather than 2 separate functions. Just make sure its before:

$subscribe_args['merge_vars'] = $merge_vars;

Then you have a TICKETPARAM merge var in your list, so within your campaign your should be able to do something like:

http://yourdomain.com/?ee=ee-txn-tickets-url&token=*|HTML:TICKETPARAM|*

And that will generate the ticket url for that user on the fly, see:

http://kb.mailchimp.com/merge-tags/all-the-merge-tags-cheat-sheet?_ga=1.193870446.2130253608.1417664339#Content-encoding-merge-tags

Note the above is not fully tested or supported, if you need further help with this you may need to contact a developer to pull the details over for you.

  • This reply was modified 7 years, 6 months ago by  Tony. Reason: Code formatting


Railpromo

October 5, 2016 at 9:01 am

Dear Tony,
Thanks again! I tested this, but for some reason there’s still nothing passed to Mailchimp. The curious thing is that it works fine for the event date.

		//Use the first datetime.
		$datetime = reset($datetimes);
		//Add the 'EVENTDATE' merge var and use the datetimes start_date for the value.
		$merge_vars['EVENTDATE'] = $datetime->start_date( 'Y-m-d' );
		//Add the ticket url section merge var.
		$reg_url_link = $registration->reg_url_link();
		$merge_vars['TICKETURL'] = $reg_url_link;
		//Add the merge vars back into the subscriptions args.
		$subscribe_args['merge_vars'] = $merge_vars;

I named it TICKETURL because I already had that merge var set up.

Both TICKETURL and EVENTDATE are set up identically (but for the field type of course, website vs. date field). Is there a clear way to check whether the variable is actually assigned a value and send to Mailchimp, just to evaluate whether the problem is at Mailchimp’s side or at the website level?


Tony

  • Support Staff

October 5, 2016 at 9:20 am

website vs. date field

Change the field type of your TICKETURL merge var to Text, its not a URL any more.

You may need to remove and recreate it to do so, or to test just create another and set that value above, for example TICKETURL2 as a text field, then send the value to both fields and see if it passes over.

Is there a clear way to check whether the variable is actually assigned a value and send to Mailchimp, just to evaluate whether the problem is at Mailchimp’s side or at the website level?

Not easily.

You would need to output the merge vars and capture the value within the ajax request.


Railpromo

October 5, 2016 at 9:29 am

Thank you Tony, we’re getting somewhere!
Now indeed a string is passed to Mailchimp, e.g. 1-c44ebada63f3e4c7a05d4b3b898e28cd
Checking the KB article, the HTML: part in the merge tag should leave to string unedited upon inclusion, i.e. http://www.panoramarail.nl/ee=ee-txn-tickets-urltoken=1-c44ebada63f3e4c7a05d4b3b898e28cd should be the link to the ticket in this case, but this get’s a WordPress page not found issue, although I think that might be because of WordPress’ permalink structure…


Tony

  • Support Staff

October 5, 2016 at 10:17 am

Apologies, the forum messed with my link formatting in the example above (fixed now).

That link should be:

http://www.panoramarail.nl/?ee=ee-txn-tickets-url&token=1-c44ebada63f3e4c7a05d4b3b898e28cd

Note the link now includes ? at the beginning and & before ‘token’


Railpromo

October 5, 2016 at 1:02 pm

Cool, works like a charm. Is there also a similar variable which holds the URL for the change attendee information option as displayed upon completion of the registration? Since, in my case, only the primary registrant has to enter information (attendee details), there’s always just one linked shown at the end.


Tony

  • Support Staff

October 6, 2016 at 2:56 am

EE includes all of this information within the standard messages so it is available, but you will need to find how the link is created and pass over the needed information to mailchimp.

Take a look within the Receipt message for an example of the [PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK] shortcode.

There is also the [RECIPIENT_EDIT_REGISTRATION_LINK] which works in a similar way.

See how those shortcodes output the link and re-build that within MailChimp.

Note they both use the reg_url_link() value you passed over for the ticket, just in a different link. You may want to change the merge var to a different name as it can be used for multiple different functions.


Railpromo

October 6, 2016 at 3:04 am

Thanks for your great support! 🙂


Tony

  • Support Staff

October 6, 2016 at 4:53 am

You’re most welcome 🙂

The support post ‘Ticket url to Mailchimp’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso