Update 800 hyperlinks with UTM tracking

Community Beginner ,
Mar 03, 2022 Mar 03, 2022

Copy link to clipboard

Copied

My client would like to add tracking to all their hyperlinks across 7 files, between 800-2200 SKUs each. This is not a batch find and replace situation, UTM was never used up until this new request,  so I don't think IDML option will work.

 

Is there a way to batch add the UTM tracking to all hyperlinks?

TOPICS
How to , Scripting

Views

140

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Mar 03, 2022 Mar 03, 2022
Assuming the UTM needs to be appended to the end of all existing Hyperlink URL Destinations in the document:  var hlds = app.activeDocument.hyperlinkURLDestinations; var utm = "?utm=blahblah"; for (var i = 0; i < hlds.length; i++) { hlds[i].destinationURL += utm; }

Likes

Translate

Translate
Adobe Community Professional ,
Mar 03, 2022 Mar 03, 2022

Copy link to clipboard

Copied

Assuming the UTM needs to be appended to the end of all existing Hyperlink URL Destinations in the document: 

var hlds = app.activeDocument.hyperlinkURLDestinations;
var utm = "?utm=blahblah";
for (var i = 0; i < hlds.length; i++) {
    hlds[i].destinationURL += utm; 
}

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 03, 2022 Mar 03, 2022

Copy link to clipboard

Copied

Wow - Brian - brillant. Haven't worked with scripts very much. What/where exactly am I using this beautiful set of instructions?

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 03, 2022 Mar 03, 2022

Copy link to clipboard

Copied

The above code is a jsx script. This explains how to install and use it. You'll need to run it on an open document (won't do all docs at once--that costs extra 😉 )

 

https://creativepro.com/how-to-install-a-script-in-indesign-that-you-found-in-a-forum-or-blog-post/

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 03, 2022 Mar 03, 2022

Copy link to clipboard

Copied

Many thanks kind sir!

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 03, 2022 Mar 03, 2022

Copy link to clipboard

Copied

Just had to fix a spelling mistake to make this script work. Thank you so very much!

Would this script also work to find and replace if they change the UTM info in the future?

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 03, 2022 Mar 03, 2022

Copy link to clipboard

Copied

Sure, just change this line: 

hlds[i].destinationURL += utm; 

To this: 

hlds[i].destinationURL = hlds[i].destinationURL.replace("?=oldutm", "?=newutm");

Keep the double quotes 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 03, 2022 Mar 03, 2022

Copy link to clipboard

Copied

LATEST

Once Again - thank you very much!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines