Dynata Link Embedding with surveydown

Tutorial
A brief tutorial on how to embed Dynata links in your surveydown survey.
Author

Pingfan Hu

Published

July 7, 2025

1 Motivation

When you have your survey link ready, you might want to cooperate with Dynata to recruit your survey. Dynata has 2 link checkpoints:

  1. Validate the Starting Link
  2. Redirect to the Ending Link

The Starting Link ensures that the respondent is legitimate, and the Ending Link redirects them to the correct ending pages that Dynata prepares based on your designed filtering mechanism.

The Starting Link is ALREADY there as provided by Dynata. You just need to capture the values and validate it. There is one unique Starting Link for each respondent.

The Ending Link, on the other hand, should be generated by you as a redirection link back to Dynata. Usually there should be 3 types of Ending Links: “Complete”, “Screenout”, and “Quotafull”. Each of them has a different rst value in the link. We’ll talk about them later.

This tutorial is based on my previous experience of cooperating with Dynata, in which case I used formr and defined the related values and mechanisms in the XML files and the survey runs. Our lab has now moved on with surveydown, which is granted with similar capabilities that handle the starting and completion links as required by Dynata.

4 What You Should Do

So in the end, what you should do? Here is a walk-through:

4.3 Example R Codes

# Server setup
server <- function(input, output, session) {
  ### Start of Dynata setup ###

  # Save your secret key in the .env file
  secret_key <- Sys.getenv("SECRET_KEY")

  # Obtain parameters from the URL
  url_pars <- reactive({sd_get_url_pars()})
  psid <- reactive({url_pars()["psid"]})
  keyid <- reactive({url_pars()["_k"]})
  signature_start <- reactive({url_pars()["_s"]})

  # Starting Link Validation
  is_valid_start <- reactive({
    # Get the current URL path (everything after the domain)
    url_path <- session$clientData$url_pathname
    text_start <- paste0(url_path, "?psid=", psid(), "&_k=", keyid())
    signature_start_validate <- hmac(
      key = secret_key,
      object = text_start,
      algo = "sha256",
      serialize = FALSE
    )
    !is.na(psid()) &&
      psid() != "" &&
      (signature_start() == signature_start_validate)
  })

  # Create ending links
  ending_links <- reactive({
    # Ending texts for "Complete", "Screenout", and "Quotafull"
    text_end_1 <- paste0("/projects/end?rst=1&psid=", psid(), "&_k=", keyid())
    text_end_2 <- paste0("/projects/end?rst=2&psid=", psid(), "&_k=", keyid())
    text_end_3 <- paste0("/projects/end?rst=3&psid=", psid(), "&_k=", keyid())

    # Ending signatures (_s) for "Complete", "Screenout", and "Quotafull"
    signature_end_1 <- hmac(
      key = secret_key,
      object = text_end_1,
      algo = "sha256",
      serialize = FALSE
    )
    signature_end_2 <- hmac(
      key = secret_key,
      object = text_end_2,
      algo = "sha256",
      serialize = FALSE
    )
    signature_end_3 <- hmac(
      key = secret_key,
      object = text_end_3,
      algo = "sha256",
      serialize = FALSE
    )

    # Ending links of "Complete", "Screenout", and "Quotafull"
    list(
      complete = paste0(
        "https://dkr1.ssisurveys.com/projects/end?rst=1&psid=",
        psid(),
        "&_k=",
        keyid(),
        "&_s=",
        signature_end_1
      ),
      screenout = paste0(
        "https://dkr1.ssisurveys.com/projects/end?rst=2&psid=",
        psid(),
        "&_k=",
        keyid(),
        "&_s=",
        signature_end_2
      ),
      quotafull = paste0(
        "https://dkr1.ssisurveys.com/projects/end?rst=3&psid=",
        psid(),
        "&_k=",
        keyid(),
        "&_s=",
        signature_end_3
      )
    )
  })

  ## Redirect buttons
  sd_redirect(
    id = "redirect_complete",
    url = ending_links()$complete,
    button = TRUE,
    label = "Back to panel"
  )

  sd_redirect(
    id = "redirect_screenout",
    url = ending_links()$screenout,
    button = TRUE,
    label = "Back to panel"
  )

  sd_redirect(
    id = "redirect_quotafull",
    url = ending_links()$quotafull,
    button = TRUE,
    label = "Back to panel"
  )

  ### End of Dynata set up ###

  # Rest of the server logic...
}

5 Other Resources

5.1 A Working Template of External Redirect

Start with the Extrenal Redirect template. This is a working template without HMAC-SHA256 encryption. It has the basic components of a survey that redirects to an external link. You can modify it to fit your Dynata needs.

5.2 Dynata Official Documentation

Check out the full official guidance form Dynata here.